Skip to content

Instantly share code, notes, and snippets.

@jeanPokou
Last active November 10, 2018 01:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeanPokou/962830d5a7106bbf2d6e68175edfee14 to your computer and use it in GitHub Desktop.
Save jeanPokou/962830d5a7106bbf2d6e68175edfee14 to your computer and use it in GitHub Desktop.
Java Observer Pattern
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