12 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.
Note Be sure to read the introduction to part 4 of the book for important information about design patterns in general and to learn how this and subsequent chapters teach each pattern.