Skip to content

Instantly share code, notes, and snippets.

@akimichi
Created May 7, 2012 04:08
Show Gist options
  • Save akimichi/2625850 to your computer and use it in GitHub Desktop.
Save akimichi/2625850 to your computer and use it in GitHub Desktop.
family.scala
trait Family {
type M <: Mother
type F <: Father
type C <: Child
class Father ( val name: String ) {
def kiss (m:M) =
println ( "Showing signs of affect ion towards " + m.name)
}
class Mother ( val name: String )
class Child ( val name: String ) {
def askForhelp (m:M) = println ( "Screeaaaaming at " + m.name)
}
}
object UpperClassFamily extends Family {
type F = Father ; type M = Mother ; type C = PoliteChild
class Mother (name: String , val lastName : String ) extends super.Mother(name)
class PoliteChild (name: String ) extends Child (name) {
override def askForhelp (m:M) =
println ( "Asking " + m.name + m.lastName + " for help" )
}
}
object StandardFamily extends Family {
type F = Father ; type M = Mother ; type C = Child
}
def assignFamily (f: Family ) = ()
val father = new StandardFamily.Father("John")
val upperClassMother = new UpperClassFamily.Mother("Dorthea III")
father.kiss(upperClassMother) / / illegal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment