Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- class Player
- {
- void move()
- {
- move(speed);
- moveNotification();
- }
- }
- class DAPlayer : Player
- {
- void moveNotification() override
- {
- sendText("You are moving %s", this->speed);
- }
- }
- //
- Perhaps just callbacks.
- class Player
- {
- void Move()
- {
- player.Move();
- moveNotification();
- }
- moveNotification()
- {
- Callbacks(moveCallback).Call(position); // Perhaps only share the position.
- // Rather than the whole object.
- // Otherwise, we may need to add some getters.
- }
- addNotification(type, callback)
- {
- Callbacks.Insert(type, callback);
- }
- }
- //
- Perhaps a decorator since yegor loves them
- class Player
- {
- void move()
- {
- jump(); // Here's a problem. The player will not get notified since it will not call the decorator.
- }
- void jump()
- {
- }
- }
- class DAPlayer
- {
- Player(IPlayer) { }
- void move()
- {
- player.move();
- player.sendText("You are moving %s", player.speed);
- }
- void jump()
- {
- player.jump();
- player.sendText("You are jumping %s", player.speed);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement