Design Pattern Examples
Overview of object-oriented design patterns
ObserverForBinary Class Reference

Represents an observer that prints out the current number from the Subject in binary. More...

#include <Observer_Class.h>

Inheritance diagram for ObserverForBinary:
Inheritance graph
Collaboration diagram for ObserverForBinary:
Collaboration graph

Public Member Functions

 ObserverForBinary (INumberProducer::shared_ptr_t numberProducer)
 Constructor.
 
void NumberChanged ()
 Called whenever the number is changed in the number producer. This observer instance must first be subscribed to the number producer to receive calls on this method.
 
- Public Member Functions inherited from IObserverNumberChanged
virtual ~IObserverNumberChanged ()
 Virtual destructor required for interfaces in abstract classes.
 
virtual void NumberChanged ()=0
 This is called whenever the number in the ObserverSubject_NumberProducer object is changed.
 

Private Attributes

INumberProducer::shared_ptr_t _numberProducer
 The number producer from which to get the current number.
 

Additional Inherited Members

- Public Types inherited from IObserverNumberChanged
using shared_ptr_t = std::shared_ptr< IObserverNumberChanged >
 Alias to make it easier to use this shared pointer.
 

Detailed Description

Represents an observer that prints out the current number from the Subject in binary.

Definition at line 127 of file Observer_Class.h.

Constructor & Destructor Documentation

◆ ObserverForBinary()

Constructor.

Parameters
numberProducerA number producer as represented by an INumberProducer interface. Cannot be null.

Definition at line 141 of file Observer_Class.h.

Member Function Documentation

◆ NumberChanged()

void NumberChanged ( )
inlinevirtual

Called whenever the number is changed in the number producer. This observer instance must first be subscribed to the number producer to receive calls on this method.

In this example, this notification handler prints out the current number in binary.

Implements IObserverNumberChanged.

Definition at line 160 of file Observer_Class.h.

References ObserverForBinary::_numberProducer, Helpers::formatstring(), and Helpers::uint32_to_binary().

Member Data Documentation

◆ _numberProducer

INumberProducer::shared_ptr_t _numberProducer
private

The number producer from which to get the current number.

Definition at line 133 of file Observer_Class.h.

Referenced by ObserverForBinary::NumberChanged(), ObserverForDecimal::NumberChanged(), and ObserverForHexaDecimal::NumberChanged().


The documentation for this class was generated from the following file: