Summary

In learning the Observer pattern, I looked at which object is best able to handle future variation. In the case of the Observer pattern, the object that is triggering the event—the Subject—cannot anticipate every object that might need to know about the event. To solve this, I create an Observer interface and require that all Observers be responsible for registering themselves with this Subject.

While I focused on the Observer pattern during the chapter, it is worth pointing out several object-oriented principles that are used in the Observer pattern.

Concept Discussion
Objects are responsible for themselves There were different kinds of Observers but all gathered the information they needed from the Subject and took the action appropriate for them on their own.
Abstract class The Observer class represents the concept of objects that needed to be notified. It gave a common interface for the subject to notify the Observers.
Polymorphic encapsulation The subject did not know what kind of observer it was communicating with. Essentially, the Observer class encapsulated the particular Observers present. This means that if I get new Observers in the future, the Subject does not need to change.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.217.145.223