Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- interface Flyable {
- fly: ()=> void
- }
- class Animal {
- constructor(public name: string) {}
- }
- class Mamal extends Animal {}
- class Bird extends Animal implements Flyable {
- constructor(name: string) {
- super(name);
- }
- fly(): void {
- console.log(`${this.name} the bird is flying`);
- }
- }
- class Bat extends Mamal implements Flyable {
- constructor(name: string) {
- super(name);
- }
- fly(): void {
- console.log(`${this.name} is flying like bats`);
- }
- }
- class HummingBirdFactory {
- static createHummingBird(bird: Bird, bat: Bat): HummingBird {
- return new HummingBird(bird.name, bat.fly);
- }
- }
- class HummingBird {
- name: string;
- fly: () => void;
- constructor(name: string, fly: () => void) {
- this.name = name;
- this.fly = fly;
- }
- }
- const bird = new Bird('Humming Bird');
- const bat = new Bat('Bat');
- const hummingBird = HummingBirdFactory.createHummingBird(bird, bat);
- hummingBird.fly();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement