Code example

Now that we have presented our class diagram, let's take a look at the source code for the example. First of all, let's see the model classes we have:

trait Notifiable {  def notify(message: String)}case class Student(name: String, age: Int) extends Notifiable {  override def notify(message: String): Unit = {    System.out.println(s"Student $name was notified with message:    '$message'.")  }}case class Group(name: String)

The Notifiable trait in the preceding code is not needed in the current example; however, for example, if we add teachers, then it would be useful in the cases where we want to send notifications to everyone in the same group. The classes in the previous code can have their own independent functionality.

Our Mediator ...

Get Scala Design Patterns - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.