In Scala we have something called case classes. These make excellent messages since they are both immutable and great to pattern match on.
class Person {
def tell {
println( "here's a little story ..." )
}
}
val singingPerson = new Person with Singer
singingperson.sing
def cast( p: Person ) {
p match {
case s: Singer => s.sing
case _ => p.tell
}
}
No comments:
Post a Comment