Chapter 9. Observer
Clients ordinarily gather information from an interesting object by calling its methods. But when an interesting object changes, a problem arises: How do clients that depend on the object's information know that the information has changed?
You may encounter designs that make an object responsible for informing clients when an interesting aspect of the object changes. The problem with this is that the knowledge of which attributes about an object are interesting lies with the client. The interesting object shouldn't accept responsibility for updating the client.
One solution is to arrange for clients to be informed when the object changes and leave it to the clients to follow up with interrogations about the object's new state. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access