Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ---------Framework:---------
- abstract class Engine {
- abstract type MixIn
- class Base(val children: Seq[Base]) extends MixIn
- abstract def doSomething(base: Base)
- final class Spec1(val foo: String, children: Seq[Base]) extends Base(children)
- final class Spec2(val bar: String, children: Seq[Base]) extends Base(children)
- }
- object Engine {
- def runExample(engine: Engine) {
- val spec1 = new engine.Spec1("foo", Seq.empty)
- engine.doSomething(spec1)
- val spec2 = new engine.Spec2("foo", Seq(new Spec1("foo", Seq.empty)))
- engine.doSomething(spec2)
- }
- }
- // ---------Client:---------
- class ConcreteEngine {
- trait Height {
- val height = if(children.isEmpty()) 0 else children.map{_.height}.max
- }
- override type MixIn = Height
- override def doSomething(base: Base) {
- println("Node @ " + base.height)
- }
- }
- object Main extends App {
- Engine.run(new ConcreteEngine())
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement