这两天做MVC,其中有OBSERVER模式的应用,简单实现了下接口。

Subject.h

#ifndef _SUBJECT_H
#define _SUBJECT_H

#include "Observer.h"
#define MAX_OBSERVER_NUM 10

class Subject
{
      public:
             virtual ~Subject();
             virtual void Attach(Observer *pObserver);
             virtual void Detach(Observer *pObserver);      // 未实现
             virtual void Notify();
      protected:
                Subject(int m = MAX_OBSERVER_NUM);
      private:
              Observer **ppObserver;
              int max;
              int size;
};

#endif

Read more