Last active
April 28, 2019 15:12
-
-
Save benfluleck/3166079b9546517b6d574b08eabbe598 to your computer and use it in GitHub Desktop.
Open Closed 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{} | |
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