Skip to content

Instantly share code, notes, and snippets.

@marcus-sa
Last active January 11, 2019 10:53
Show Gist options
  • Save marcus-sa/c8efdd7ed61733eebde6fe677bde4328 to your computer and use it in GitHub Desktop.
Save marcus-sa/c8efdd7ed61733eebde6fe677bde4328 to your computer and use it in GitHub Desktop.
interface IBird {
canFly(): boolean;
}
class Crow implements IBird {
public canFly() {
return true;
}
}
class Goose implements IBird {
public canFly() {
return true;
}
}
class App {
constructor(birds: IBird[]) {
birds.forEach(bird => {
const { name } = bird.constructor;
if (bird.canFly()) {
console.log(name + " can fly");
} else {
console.log(name + " can't fly");
}
});
}
}
const container = new Container();
container.bind(InterfaceSymbol<IBird>(), [Crow, Goose]);
container.startBootstrap(App);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment