Created
February 10, 2012 07:41
-
-
Save debasishg/1787464 to your computer and use it in GitHub Desktop.
New Cake pattern (from @etorreborre)
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 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