Proof of concept for using mixin to decorate with delegation rather than inheritance (the pattern I normally see)
Last active
August 29, 2015 14:25
-
-
Save natebosch/917258889251d7d0ae21 to your computer and use it in GitHub Desktop.
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
void main() { | |
print( new Foo().foo); | |
print( new ConcreteDelegating().foo); | |
print( new ConcreteDelegating().bar); | |
} | |
class Foo { | |
String get foo => 'original foo'; | |
String get bar => 'original bar'; | |
} | |
abstract class DelegatingFoo implements Foo { | |
Foo get delegate; | |
String get foo => delegate.foo; | |
String get bar => delegate.bar; | |
} | |
class ConcreteDelegating extends Object with DelegatingFoo { | |
final Foo delegate = new Foo(); | |
String get foo => 'Decorated!' + delegate.foo; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment