Advertisement
Guest User

Untitled

a guest
Jul 24th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. //
  2.  
  3. class Player
  4. {
  5. void move()
  6. {
  7. move(speed);
  8. moveNotification();
  9. }
  10. }
  11.  
  12. class DAPlayer : Player
  13. {
  14. void moveNotification() override
  15. {
  16. sendText("You are moving %s", this->speed);
  17. }
  18. }
  19.  
  20. //
  21. Perhaps just callbacks.
  22.  
  23. class Player
  24. {
  25. void Move()
  26. {
  27. player.Move();
  28. moveNotification();
  29. }
  30.  
  31. moveNotification()
  32. {
  33. Callbacks(moveCallback).Call(position); // Perhaps only share the position.
  34. // Rather than the whole object.
  35. // Otherwise, we may need to add some getters.
  36. }
  37.  
  38. addNotification(type, callback)
  39. {
  40. Callbacks.Insert(type, callback);
  41. }
  42. }
  43.  
  44. //
  45. Perhaps a decorator since yegor loves them
  46.  
  47. class Player
  48. {
  49. void move()
  50. {
  51. jump(); // Here's a problem. The player will not get notified since it will not call the decorator.
  52. }
  53.  
  54. void jump()
  55. {
  56.  
  57. }
  58. }
  59.  
  60. class DAPlayer
  61. {
  62. Player(IPlayer) { }
  63.  
  64. void move()
  65. {
  66. player.move();
  67. player.sendText("You are moving %s", player.speed);
  68. }
  69.  
  70. void jump()
  71. {
  72. player.jump();
  73. player.sendText("You are jumping %s", player.speed);
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement