Event-Driven Programming in C++ 1.0
A case study on event-driven programming in C++
Loading...
Searching...
No Matches
observer::Subject Class Reference

The Subject class manages a list of observers and notifies them of events. More...

#include <subject.hpp>

Public Member Functions

void addObserver (IObserver *observer)
 Adds an observer to the list of observers.
 
void removeObserver (IObserver *observer)
 Removes an observer from the list.
 
void notify (const std::string &message)
 Notifies all registered observers of an event.
 

Private Attributes

std::vector< IObserver * > observers
 Container storing pointers to the registered observers.
 

Detailed Description

The Subject class manages a list of observers and notifies them of events.

The Subject class provides methods to add and remove observers, as well as to notify all registered observers by calling their onNotify() method.

Member Function Documentation

◆ addObserver()

void observer::Subject::addObserver ( IObserver observer)
inline

Adds an observer to the list of observers.

Parameters
observerA pointer to an object implementing the IObserver interface.

◆ notify()

void observer::Subject::notify ( const std::string &  message)
inline

Notifies all registered observers of an event.

This method calls the onNotify() function on each observer, passing the provided message.

Parameters
messageA string describing the event.

◆ removeObserver()

void observer::Subject::removeObserver ( IObserver observer)
inline

Removes an observer from the list.

Parameters
observerA pointer to the observer to remove.

Member Data Documentation

◆ observers

std::vector<IObserver*> observer::Subject::observers
private

Container storing pointers to the registered observers.


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