Last active
October 2, 2022 16:22
-
-
Save shian15810/fa8563348c2dc4e04e6e541352c563fd to your computer and use it in GitHub Desktop.
Inheritance Breaks Encapsulation: https://www.youtube.com/watch?v=EfxYiAN6YME
This file contains 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 { | |
protected bark(): void { | |
// console.log("bark"); | |
this.barkMany(1); | |
} | |
protected barkMany(n: number): void { | |
for (let i = 0; i < n; i++) { | |
// this.bark(); | |
console.log("bark"); | |
} | |
} | |
} | |
class VerboseDog extends Dog { | |
public barkMany(n: number): void { | |
console.log("As a dog, I say: "); | |
for (let i = 0; i < n; i++) { | |
this.bark(); | |
} | |
} | |
} | |
new VerboseDog().barkMany(2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment