liveBook · Manning

Observer

As explained in Object-Oriented Software Design in C++

A book-specific interface whose implementors receive update notifications from a Subject.

Observer defines a one-to-many dependency between a Subject and its subscribers. The Subject keeps registered observers, and notify() calls each observer’s update() method when new content arrives. section 12.1.3

A typical implementation provides:

  • Independent subscribers such as LogReport, GraphReport, TableReport, and FanClubReport, each processing updates differently. section 12.1.3

Baseball reports

BaseballReporter publishes events. Each report registers with attach(), receives update(), and can retrieve the current Event. FanClubReport filters for George, produces a bulletin, then detaches itself.

How Object-Oriented Software Design in C++ covers it

How deep it goes
Explains interfaces, subscription management, polymorphic notification, and current-event retrieval through C++ listings.
Examples
Uses BaseballReporter with log, graph, table, and fan-club reports processing generated baseball events.
What you can do after
Apply it via Subject, Observer, attach(), detach(), notify(), and update() to add subscribers without changing publisher code.
How it connects
Ties Subject and Observer to publisher–subscriber design, polymorphism, and the Code to the Interface Principle.

This explainer was generated by Manning's knowledge graph from the text of Object-Oriented Software Design in C++. The section links point to the parts of the book it draws on.