WHAT’S IN THIS CHAPTER?
- Learning how the Observer Pattern leads to loosely coupled code
- Improving the reliability of the Observer Pattern with argument checking
- Coding a game using the Mediator Pattern
- Using the Interface Segregation Principle to simplify development with the Mediator Pattern
- Unit-testing a mediator and its colleagues
WROX.COM CODE DOWNLOADS FOR THIS CHAPTER
The wrox.com code downloads for this chapter are found at
Most programs you have written were probably written to achieve some goal. The architecture may have been the conventional, top-down variety that you learned along with object-oriented programming. The architectures you will consider in this chapter are different. They allow independent parts to interact in a decentralized manner. The overall goal happens as if by magic.
The patterns in question are known as the Observer and Mediator. They are similar in that they are decentralized, but the means of communication differ.
ENSURING RELIABLE USE OF THE OBSERVER PATTERN
If you’ve subscribed to daily newspaper delivery, you’ve participated in a real-life implementation of the Observer Pattern. By sending your subscription card to the newspaper publisher, you alerted the publisher that you would like to have ...