Skip to content

Instantly share code, notes, and snippets.

@gayashanbc
Last active July 22, 2018 18:32
Show Gist options
  • Save gayashanbc/6de4f00d684083f42804c4ab19436d7f to your computer and use it in GitHub Desktop.
Save gayashanbc/6de4f00d684083f42804c4ab19436d7f to your computer and use it in GitHub Desktop.
Header file of the Subject class (Observer Pattern in C++)
//
// Created by shan on 4/7/17.
//
#ifndef OBSERVER_PATTERN_SUBJECT_HPP
#define OBSERVER_PATTERN_SUBJECT_HPP
#include "Observer.hpp"
/**
* Interface for the Subject
*/
class Subject {
public:
/**
* Register an observer
* @param observer the observer object to be registered
*/
virtual void registerObserver(Observer *observer) = 0;
/**
* Unregister an observer
* @param observer the observer object to be unregistered
*/
virtual void removeObserver(Observer *observer) = 0;
/**
* Notify all the registered observers when a change happens
*/
virtual void notifyObservers() = 0;
};
#endif //OBSERVER_PATTERN_SUBJECT_HPP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment