-
-
Save kibolho/3d2efac77adfd2bf662c97805b9d8cd5 to your computer and use it in GitHub Desktop.
SOLID - Interface Segregation 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 Interface | |
interface Bird { | |
fly(): void; | |
walk(): void; | |
} | |
class Penguin implements Bird { | |
public fly() { | |
throw new Error('Unfortunately, Penguin can not fly!'); | |
} | |
public walk() { | |
/// ... | |
} | |
} | |
class Hawk implements Bird { | |
public fly() { | |
/// ... | |
} | |
public walk() { | |
/// ... | |
} | |
} |
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
// Good Interface | |
interface CanWalk { | |
walk(): void; | |
} | |
interface CanFly { | |
fly(): void; | |
} | |
class Penguin implements CanWalk { | |
public walk() { | |
/// ... | |
} | |
} | |
class Hawk implements CanFly, CanWalk { | |
public fly() { | |
/// ... | |
} | |
public walk() { | |
/// ... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment