Skip to main content

IObserver

Namespace: UTILSLIB  ·  Library: Utilities Library

#include <utils/observerpattern.h>

class UTILSLIB::IObserver

DECLARE INTERFACE OBSERVER.

The IObserver interface provides the base class of every observer of the observer design pattern.

src/examples/ex_utils/main.cpp
// A subject notifies every attached observer; observers pull the state they need
class Counter : public Subject
{
public:
void increment()
{
++m_value;
notify();
}
int value() const
{
return m_value;
}

private:
int m_value = 0;
};

class LastSeen : public IObserver
{
public:
void update(Subject* pSubject) override
{
m_seen = static_cast<Counter*>(pSubject)->value();
}
int seen() const
{
return m_seen;
}

private:
int m_seen = -1;
};

Inheritance​


Public Methods​

~IObserver()​

Destroys the IObserver.


update(pSubject)​

Updates the IObserver.

Parameters:

  • pSubject : *Subject ** pointer to the subject where observer is attached to.

Example​

Used in examples​

ex_utils​

Utilities library: buffers, observers, logging, file formats, montages, layouts and reports.

src/examples/ex_utils/main.cpp, line 97
class LastSeen : public IObserver
{
public:
void update(Subject* pSubject) override
{
m_seen = static_cast<Counter*>(pSubject)->value();
}
int seen() const
{
return m_seen;
}

Authors of this file​