Skip to content

Instantly share code, notes, and snippets.

@thara
Created June 22, 2013 13:20
Show Gist options
  • Save thara/5840840 to your computer and use it in GitHub Desktop.
Save thara/5840840 to your computer and use it in GitHub Desktop.
Dependency Injection with Implicit Interfaces & Mix-in in Dart.
main () {
new Service().execute();
new AwesomeService().execute();
}
class Repository {
List<String> find() => ["data1", "data2"];
}
class Service {
Repository get repository => new Repository();
void execute() => print(repository.find());
}
class AwesomeRepository implements Repository {
List<String> find() => ["awesomeData1", "awesomeData2"];
}
abstract class AwesomeRepositoryModule {
Repository get repository => new AwesomeRepository();
}
typedef AwesomeService = Service with AwesomeRepositoryModule;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment