Last active
April 28, 2019 15:19
-
-
Save benfluleck/ddbc723989fb0ca44856ba85ade1b0d6 to your computer and use it in GitHub Desktop.
Liskov Substitution Principle
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
// bad | |
class Bird{ | |
fly(){ | |
console.log('I can fly') | |
} | |
} | |
class Duck extends Bird { | |
constructor(){ | |
super(); | |
} | |
fly(){ | |
} | |
} | |
// Ostrich breaks the Liskov Substitution principle as it can not be replaced for the base class | |
class Ostrich extends Bird { | |
constructor(){ | |
super(); | |
} | |
fly(){ | |
} | |
} | |
// good | |
class Bird{} | |
class FlyingBird extends Bird { | |
fly(){ | |
} | |
} | |
class LandBird extends Bird { | |
} | |
class Duck extends FlyingBird { | |
constructor(){ | |
super(); | |
} | |
fly(){ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment