Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. class Animal {
  2. func fly() {
  3. // TODO: flying logic
  4. }
  5.  
  6. func eat() {
  7. // TODO: eating logic
  8. }
  9. }
  10.  
  11. class Cat: Animal {
  12. override func fly() {
  13. //Hi I'm a cat I cant fly,
  14. ///here is the Breaking of LSP, I have a different behavior
  15. }
  16. }
  17.  
  18. //this is bad, why, cause it have two different responsibilities
  19. protocol Animal {
  20. func fly()
  21. func eat()
  22. }
  23. //to it write
  24. protocol Flyable {
  25. func fly()
  26. }
  27. protocol Feedable {
  28. func eat()
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement