Skip to content

Instantly share code, notes, and snippets.

@natebosch
Last active August 29, 2015 14:25
Show Gist options
  • Save natebosch/917258889251d7d0ae21 to your computer and use it in GitHub Desktop.
Save natebosch/917258889251d7d0ae21 to your computer and use it in GitHub Desktop.

Proof of concept for using mixin to decorate with delegation rather than inheritance (the pattern I normally see)

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