Merge pull request #9603 from eugenp/KTLN-137

KTLN-137 move kotlin article
This commit is contained in:
Loredana Crusoveanu 2020-06-29 10:47:58 +03:00 committed by GitHub
commit 0b570caaa7
6 changed files with 0 additions and 64 deletions

View File

@ -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() }
}
}

View File

@ -1,5 +0,0 @@
package com.baeldung.observer
interface IObserver {
fun update()
}

View File

@ -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) }
}
}

View File

@ -1,8 +0,0 @@
package com.baeldung.observer.delegates
fun main() {
val newsletter = BaeldungNewsletter()
newsletter.newestArticleObservers.add { newestArticleUrl ->
println("New Baeldung article: ${newestArticleUrl}")
}
}

View File

@ -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()
}
}

View File

@ -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}")
}
}