Created
April 13, 2012 06:14
-
-
Save lyricallogical/2374314 to your computer and use it in GitHub Desktop.
単に delegate するような何かを作っておけば cake pattern でも何かできるみたいな気持ち
This file contains 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 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 } |
This file contains 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 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
最初のバージョンはなんか非対称だったので同じっぽい感じにしてみた。typo があった…