Created
May 26, 2015 18:54
-
-
Save cuipengfei/e5ed5961db8ce2921c1b to your computer and use it in GitHub Desktop.
test
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
package strategyfp | |
import strategyfp.Duck.{Fly, Quack, _} | |
abstract class Duck(f: Fly, q: Quack) { | |
def swim() = println("all ducks float") | |
def fly() = f() | |
def quack() = q() | |
} | |
object Duck { | |
type Fly = () => Unit | |
val flyWithWings = () => println("fly with wings") | |
val flyNoWay = () => println("can not fly") | |
type Quack = () => Unit | |
val realQuack = () => println("Quack") | |
val muteQuack = () => println("<<silence>>") | |
} | |
class MallardDuck extends Duck(flyWithWings, realQuack) | |
class DecoyDuck extends Duck(flyNoWay, muteQuack) | |
object DuckSimFP { | |
def main(args: Array[String]) { | |
val mallardDuck = new MallardDuck() | |
mallardDuck.fly() | |
mallardDuck.quack() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment