Skip to content

Instantly share code, notes, and snippets.

@benfluleck
Last active April 28, 2019 15:12
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/3166079b9546517b6d574b08eabbe598 to your computer and use it in GitHub Desktop.
Save benfluleck/3166079b9546517b6d574b08eabbe598 to your computer and use it in GitHub Desktop.
Open Closed Principle
// Bad
class Bird{}
class FlyingBird extends Bird {
constructor(type, name){
super();
this.name = name
}
flightSpeed(){
if(this.name === "parrot" || this.name === "dove"){
return ('I can fly medium-fast')
}
else if(this.name === "eagle") {
return ('I can fly fast)
}
}
}
// Good
class BirdTwo{}
class FlyingBird extends BirdTwo{
constructor(type, name){
super();
this.name = name
}
flightSpeed(){
return 'I can fly'
}
}
class mediumFlyer extends FlyingBird{
constructor(type, name){
super();
this.name = name
}
flightSpeed(){
return 'I can fly medium fast'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment