Created
October 24, 2013 21:24
-
-
Save danclien/7145300 to your computer and use it in GitHub Desktop.
Bare bones to implement the Cake Pattern down the road.
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
/***** Dependency *****/ | |
trait EngineComponent { | |
val engine: Engine | |
// class Engine { | |
// def start: Unit = println("engine.start: vroom") | |
// } | |
} | |
/***** Dependent implementation *****/ | |
trait CarComponent { | |
//this: EngineComponent => //Need to declare your dependency anyways | |
// class Car { | |
// def turnKey: Unit = { | |
// println("Attempting to start the car...") | |
// engine.start | |
// } | |
// } | |
} | |
/***** Containers *****/ | |
object Container extends CarComponent with EngineComponent { | |
val engine = new Engine | |
val car = new Car | |
} | |
/***** Example usage *****/ | |
val car = Container.car | |
car.turnKey |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment