observer_pattern
-
namespace observer_pattern
Namespace for the Observer pattern.
-
class ConcreteObserver : public observer_pattern::Observer
- #include <observer.hpp>
Concrete implementation of an Observer.
Subclassed by TestObserver
Public Functions
Constructor for ConcreteObserver.
- Parameters:
name – The name of the observer.
subject – The subject to observe.
-
inline std::string getName() const
Get the name of the observer.
- Returns:
The name of the observer.
-
inline virtual void update() override
Updates the observer when notified by the subject.
-
class ConcreteSubject : public observer_pattern::Subject
- #include <observer.hpp>
Concrete implementation of a Subject.
Public Functions
Attach an observer to the subject.
- Parameters:
observer – The observer to attach.
Detach an observer from the subject.
- Parameters:
observer – The observer to detach.
-
inline virtual void notify() override
Notify all attached observers of a change.
-
inline virtual std::string getState() const override
Get the current state of the subject.
- Returns:
The current state as a string.
-
inline virtual void setState(const std::string &newState) override
Set the state of the subject and notify observers.
- Parameters:
newState – The new state of the subject.
-
class Observer
- #include <observer.hpp>
Abstract base class representing an observer in the Observer pattern.
Subclassed by observer_pattern::ConcreteObserver
Public Functions
-
virtual ~Observer() = default
Virtual destructor for cleanup of derived classes.
-
virtual void update() = 0
Called to notify the observer of changes in the subject.
-
virtual ~Observer() = default
-
class Subject
- #include <observer.hpp>
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.
Attach an observer to the subject.
- Parameters:
observer – The observer to attach.
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.
-
virtual ~Subject() = default
-
class ConcreteObserver : public observer_pattern::Observer