12 The Observer Design Pattern

 

This chapter covers

  • The Observer Design Pattern

In this chapter, we continue with the theme of sports reports generated by a college athletics department. The Observer Design Pattern supports the publisher–subscriber model, where one component creates data objects that subscriber components process individually, 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 it is over.

NOTE

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 represents the publisher–subscriber model

12.1.1 Desired design features

12.1.2 Before using the Observer Design Pattern

12.1.3 After using the Observer Design Pattern

12.1.4 The Observer’s generic model

Summary