Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. class AnimalManager {
  2. instances := []
  3.  
  4. __New() {
  5.  
  6. }
  7.  
  8. init() {
  9. this.instances.insert(new Dog())
  10. this.instances.insert(new Cat())
  11. }
  12.  
  13. feedAnimals() {
  14. for k, _animal in this.instances {
  15. if (_animal.__Class == "Animal") {
  16. _animal.feed()
  17. }
  18. }
  19. }
  20. }
  21.  
  22. class Animal {
  23. feed(howMuch) {
  24. throw Exception("I don't know how to eat yet");
  25. }
  26. }
  27.  
  28. class Dog extends Animal {
  29. feed(howMuch) {
  30. msgbox % "I'm eating " . howMuch . " food."
  31. }
  32. }
  33.  
  34. class Cat extends Animal {
  35. feed(howMuch) {
  36. msgbox % "I'm eating " . (howMuch/2) . " food because I'm a picky eater."
  37. }
  38. }
  39.  
  40. mgr := new AnimalManager ()
  41.  
  42. mgr.init();
  43. mgr.feedAnimals();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement