Skip to content

Instantly share code, notes, and snippets.

@benfluleck
Last active April 28, 2019 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benfluleck/ddbc723989fb0ca44856ba85ade1b0d6 to your computer and use it in GitHub Desktop.
Save benfluleck/ddbc723989fb0ca44856ba85ade1b0d6 to your computer and use it in GitHub Desktop.
Liskov Substitution Principle
// 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