Skip to content

Instantly share code, notes, and snippets.

@debasishg
Created February 10, 2012 07:41
Show Gist options
  • Save debasishg/1787464 to your computer and use it in GitHub Desktop.
Save debasishg/1787464 to your computer and use it in GitHub Desktop.
New Cake pattern (from @etorreborre)
trait Cake {
type Config
def config: Config
}
trait FooConfig {
// ...
}
trait FooComponent extends Cake {
type Config <: FooConfig
def foo: Foo = ...
trait Foo {
// do something here
}
}
trait BarConfig {
// ...
}
trait BarComponent extends Cake {
type Config <: BarConfig
type Bar
def bar: Bar
}
trait BazBar {
// ...
}
trait BazComponent extends BarComponent {
type Bar <: BazBar
def baz: Baz = ...
trait Baz {
// something that requires bar: BazBar
}
}
trait BinBarComponent extends BazComponent {
def bar: Bar = ...
trait Bar extends BazBar {
// ...
}
}
def main(args: Array[String]) {
val cake = new FooComponent with with BazComponent with BinBarComponent {
def config = new BarConfig with FooConfig {
// ...
}
}
// do something with cake
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment