Merge pull request #9603 from eugenp/KTLN-137
KTLN-137 move kotlin article
This commit is contained in:
commit
0b570caaa7
|
@ -1,18 +0,0 @@
|
|||
package com.baeldung.observer
|
||||
|
||||
import java.util.ArrayList
|
||||
|
||||
interface IObservable {
|
||||
val observers: ArrayList<IObserver>
|
||||
fun add(observer: IObserver) {
|
||||
observers.add(observer)
|
||||
}
|
||||
|
||||
fun remove(observer: IObserver) {
|
||||
observers.remove(observer)
|
||||
}
|
||||
|
||||
fun sendUpdateEvent() {
|
||||
observers.forEach { it.update() }
|
||||
}
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
package com.baeldung.observer
|
||||
|
||||
interface IObserver {
|
||||
fun update()
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
package com.baeldung.observer.delegates
|
||||
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
class BaeldungNewsletter {
|
||||
val newestArticleObservers = mutableListOf<(String) -> Unit>()
|
||||
var newestArticleUrl: String by Delegates.observable("") { _, _, newValue ->
|
||||
newestArticleObservers.forEach { it(newValue) }
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
package com.baeldung.observer.delegates
|
||||
|
||||
fun main() {
|
||||
val newsletter = BaeldungNewsletter()
|
||||
newsletter.newestArticleObservers.add { newestArticleUrl ->
|
||||
println("New Baeldung article: ${newestArticleUrl}")
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package com.baeldung.observer.standard
|
||||
|
||||
import com.baeldung.observer.IObservable
|
||||
import com.baeldung.observer.IObserver
|
||||
import java.util.ArrayList
|
||||
|
||||
class BaeldungNewsletter : IObservable {
|
||||
override val observers: ArrayList<IObserver> = ArrayList()
|
||||
var newestArticleUrl = ""
|
||||
set(value) {
|
||||
field = value
|
||||
sendUpdateEvent()
|
||||
}
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
package com.baeldung.observer.standard
|
||||
|
||||
import com.baeldung.observer.IObserver
|
||||
|
||||
class BaeldungReader(private var newsletter: BaeldungNewsletter) : IObserver {
|
||||
override fun update() {
|
||||
println("New Baeldung article: ${newsletter.newestArticleUrl}")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue