Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Animal {
- func fly() {
- // TODO: flying logic
- }
- func eat() {
- // TODO: eating logic
- }
- }
- class Cat: Animal {
- override func fly() {
- //Hi I'm a cat I cant fly,
- ///here is the Breaking of LSP, I have a different behavior
- }
- }
- //this is bad, why, cause it have two different responsibilities
- protocol Animal {
- func fly()
- func eat()
- }
- //to it write
- protocol Flyable {
- func fly()
- }
- protocol Feedable {
- func eat()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement