- Ducks fly and quack
- Rubber ducks don't fly and quack
- => Different fly and quack behaviour
How
- Create duckbehaviour- and flybehaviour-interfaces (Program to interface)
- Different implementation in the concrete behaviour classes.
- Duck base-class with reference to FlyBehaviour- and QuackBehaviour-interface.
- The concrete Duck-classes will then use the appropriate implementation of the behaviours. (Composition)
Geen opmerkingen:
Een reactie posten