Skip to content

Instantly share code, notes, and snippets.

@lyricallogical
Created April 13, 2012 06:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lyricallogical/2374314 to your computer and use it in GitHub Desktop.
Save lyricallogical/2374314 to your computer and use it in GitHub Desktop.
単に delegate するような何かを作っておけば cake pattern でも何かできるみたいな気持ち
trait Abs { def f(): Int }
trait ConA extends Abs { def f() = 1 }
trait ConB extends Abs { abstract override def f() = super.f + 1 }
trait Delegate extends Abs {
val abs: Abs
def f() = abs.f
}
class A { this: Abs =>
def g() = f
}
def genAbs(): Abs = new ConA with ConB {}
new A with Delegate { val abs = genAbs }
trait Abs { def f(): Int }
class ConA extends Abs { def f() = 1 }
class ConB(abs: Abs) extends Abs { def f() = abs.f + 1 }
class A(abs: Abs) { def g() = abs.f }
def genAbs() = new ConB(new ConA)
new A(genAbs)
@lyricallogical
Copy link
Author

最初のバージョンはなんか非対称だったので同じっぽい感じにしてみた。typo があった…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment