liveBook · Manning

LogReport

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

A book-specific report class that immediately prints the contents of each baseball Event object it receives.

LogReport is an Observer that subscribes to BaseballReporter and immediately prints each received baseball event as a numbered game-hits log. section 12.1.3 section 12.1.2

Its Observer-based implementation separates reporting from event production:

  • Registers itself with BaseballReporter in its constructor. section 12.1.3
  • Implements update() as the required Observer operation. section 12.1.3
  • Retrieves the current Event through the reporter and translates its hit value into text such as an out, single, double, triple, or homer. section 12.1.3 section 12.1.2
  • Maintains a count and prints each player name and result immediately. section 12.1.2

Baseball event logging

Constructing LogReport(reporter) prints the GAME HITS LOG heading and subscribes the object. Each notification then produces a line such as a numbered player hit description while GraphReport and TableReport process the same event independently. section 12.1.3 section 12.1.2

Figure 12.3 This version of the application is modeled from the Observer Design Pattern. The content publisher BaseballReporter is a subclass of Subject, and each report class implements interface Observer. Member variable observers of class Subject is a vector of subscribed observers. Each time BaseballReporter uses EventManager to create a new Event object, it points private member variable current_event to the object. Then it calls the notify() member function of superclass Subject, which iterates over the observers vector and calls the update() member function of each subscribed subscriber. Each subscriber can then decide whether to call member function get_current_event() to get the current Event object. The grayed-out portions of the diagram have not changed logically from figure 12.2.

Shows LogReport within the publisher-subscriber flow: BaseballReporter creates an Event, Subject notifies observers, and LogReport retrieves the current event. section 12.1.3

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

How deep it goes
Defines subscription, notification, event retrieval, hit translation, counting, and output, but leaves detailed formatting abbreviated.
Examples
Uses a numbered GAME HITS LOG that converts random player events into descriptions such as an out, single, double, triple, or homer.
What it assumes
Assumes basic C++ classes and pointers while demonstrating interfaces, inheritance, virtual update(), and publisher subscription.
What you can do after
Builds a concrete Observer that subscribes to BaseballReporter and formats each current Event for immediate console logging.
How it connects
Connects Observer, Subject, BaseballReporter, Event, EventMaker, and polymorphism through the baseball reporting workflow.

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.