Skip to content

Instantly share code, notes, and snippets.

@danclien
Created October 24, 2013 21:24
Show Gist options
  • Save danclien/7145300 to your computer and use it in GitHub Desktop.
Save danclien/7145300 to your computer and use it in GitHub Desktop.
Bare bones to implement the Cake Pattern down the road.
/***** 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