Created
May 7, 2012 04:08
-
-
Save akimichi/2625850 to your computer and use it in GitHub Desktop.
family.scala
This file contains 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
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