Last active
November 10, 2018 01:16
-
-
Save jeanPokou/962830d5a7106bbf2d6e68175edfee14 to your computer and use it in GitHub Desktop.
Java Observer Pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Speaker() { | |
private var message= Message("Hello") | |
private val audiences = ArrayList<Audience>() | |
fun setMessage(msg:String ) { | |
this.message.text = msg | |
notifyAudience() | |
} | |
fun addAudience(audience: Audience){ | |
audiences.add(audience) | |
} | |
fun notifyAudience() { | |
for ( audience in audiences ) { | |
audience.update(message) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment