Created
February 14, 2022 09:59
-
-
Save hellokvn/0ede7977630ed64eff31d6e31f5f78e6 to your computer and use it in GitHub Desktop.
Polymorphism - Bad
This file contains hidden or 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
class Dog { | |
public name: string; | |
constructor(name: string) { | |
this.name = name; | |
} | |
public makeSound(): void { | |
process.stdout.write('wuff wuff\n'); | |
} | |
} | |
class Cat { | |
public name: string; | |
constructor(name: string) { | |
this.name = name; | |
} | |
public makeSound(): void { | |
process.stdout.write('meow meow\n'); | |
} | |
} | |
const pocky: Cat = new Cat('Pocky'); | |
pocky.makeSound(); // -> meow meow | |
const toshii: Dog = new Dog('Pocky'); | |
toshii.makeSound(); // -> wuff wuff |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment