observer_pattern::Subject

class Subject

Abstract base class representing a subject in the Observer pattern.

Subclassed by observer_pattern::ConcreteSubject

Public Functions

virtual ~Subject() = default

Virtual destructor for cleanup of derived classes.

virtual void attach(std::shared_ptr<Observer> observer) = 0

Attach an observer to the subject.

Parameters:

observer – The observer to attach.

virtual void detach(std::shared_ptr<Observer> observer) = 0

Detach an observer from the subject.

Parameters:

observer – The observer to detach.

virtual void notify() = 0

Notify all attached observers of a change.

virtual std::string getState() const = 0

Get the state of the subject.

Returns:

The current state of the subject as a string.

virtual void setState(const std::string &state) = 0

Set the state of the subject.

Parameters:

state – The new state of the subject.