Last active
August 29, 2015 14:10
-
-
Save ebruchez/e62dd70f2727d4d700c7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Animal { def name: String; def word: String; def talk() = println(s"$name says $word") } | |
trait Flying { def fly() = println("flap flap") } | |
trait Swimming { def swim() = println("splish splash") } | |
trait Walking { def walk() = println("stomp stomp") } | |
def newAlligator = | |
new Animal with Walking with Swimming { val name = "alligator"; val word = "grrr" } | |
def newDuck = | |
new Animal with Walking with Flying with Swimming { val name = "duck"; val word = "quack" } | |
def newGoat = | |
new Animal with Walking { val name = "goat"; val word = "baa" } | |
val alligator = newAlligator | |
val duck = newDuck | |
val goat = newGoat |
This file contains hidden or 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
scala> alligator.talk() | |
alligator says grrr | |
scala> alligator.walk() | |
stomp stomp | |
scala> alligator.swim() | |
splish splash | |
scala> duck.talk() | |
duck says quack | |
scala> duck.walk() | |
stomp stomp | |
scala> duck.fly() | |
flap flap | |
scala> duck.swim() | |
splish splash | |
scala> goat.walk() | |
stomp stomp | |
scala> goat.talk() | |
goat says baa |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment