chapter twelve

12 The Observer Design Pattern

 

This chapter covers

  • The Observer Design Pattern

In this chapter, we continue the theme of sports reports generated by a college athletics department. The Observer Design Pattern supports the publisher-subscriber model, where the publisher component creates data objects that subscriber components individually process, each in its own way. The publisher component doesn’t know how the subscriber components are implemented, nor does it care what the subscribers do with the data.

Our example application monitors the progress of a baseball game. It prints game statistics both while the game is in progress and after the game is over.

Learning about design patterns

Be sure to read the introduction to part 4 for important information about design patterns in general and to learn how this and subsequent chapters teach each pattern.

12.1 The Observer Design Pattern: Publish data for multiple subscribers

12.1.1 Desired design features

12.1.2 Before using Observer

12.1.3 After using Observer

12.1.4 The Observer’s generic model

12.2 Summary