I am learning the Observer pattern and I don't understand the extra * in code provided. The Subject.h has this code
//Subject.h
#pragma once
#include<list>
#include "Observable.h"
using namespace std;
class Subject : public Observable {
public:
Subject();
~Subject();
void attach(Observer *);
void detach(Observer *);
void notify();
private:
list<Observer*>* _observers; // ----------Here there is two *
};
And the Obervable.h has this code (implementing the Observer.h...)
//Observable.h
#pragma once
#include <list>
using namespace std;
class Observer;
class Observable
{
public:
virtual ~Observable() {};
virtual void attach(Observer *) = 0;
virtual void detach(Observer *) = 0;
virtual void notify() = 0;
protected:
Observable() {};
private:
list<Observer*> _observers; // ----------Here there is only one *
};
Aucun commentaire:
Enregistrer un commentaire