Ignore:
Timestamp:
Sep 1, 2011, 11:07:47 AM (14 years ago)
Author:
Frederik Heber <heber@…>
Children:
9e776f
Parents:
451f17
git-author:
Frederik Heber <heber@…> (09/01/11 11:02:49)
git-committer:
Frederik Heber <heber@…> (09/01/11 11:07:47)
Message:

Extended Observables by NotificationChannels member variable.

  • new class Channels that aggregates Notifications.
  • NOTIFY now just takes a channel number.
  • may or may not be instantiated for a given Observable.
  • Observable just needs to add enum of all desired channels and addChannel on each of these.
  • ObserverUnitTest has been adapted.
Location:
src/Patterns/unittests/stubs
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/Patterns/unittests/stubs/ObserverStub.cpp

    r451f17 r74e0f7  
    3131{};
    3232
     33UpdateCountObserver::~UpdateCountObserver()
     34{}
     35
    3336void UpdateCountObserver::update(Observable *publisher){
    3437  updates++;
     
    127130
    128131NotificationObservable::NotificationObservable() :
    129   Observable("NotificationObservable"),
    130   notification1(new Notification(this)),
    131   notification2(new Notification(this))
    132 {}
    133 
    134 NotificationObservable::~NotificationObservable(){
    135   delete notification1;
    136   delete notification2;
     132  Observable("NotificationObservable")
     133{
     134  NotificationChannels = new Channels(this);
     135  NotificationChannels->addChannel(Operation1Notify);
     136  NotificationChannels->addChannel(Operation2Notify);
     137}
     138
     139NotificationObservable::~NotificationObservable()
     140{
     141  delete NotificationChannels;
    137142}
    138143
    139144void NotificationObservable::operation1(){
    140145  OBSERVE;
    141   NOTIFY(notification1);
     146  NOTIFY(Operation1Notify);
    142147}
    143148
    144149void NotificationObservable::operation2(){
    145150  OBSERVE;
    146   NOTIFY(notification2);
     151  NOTIFY(Operation2Notify);
    147152}
    148153
     
    153158  requestedNotification(notification),
    154159  wasNotified(false)
     160{}
     161
     162NotificationObserver::~NotificationObserver()
    155163{}
    156164
  • src/Patterns/unittests/stubs/ObserverStub.hpp

    r451f17 r74e0f7  
    1515public:
    1616  UpdateCountObserver();
     17  virtual ~UpdateCountObserver();
     18
    1719  void update(Observable *publisher);
    1820  void subjectKilled(Observable *publisher);
     
    5254public:
    5355  SuperObservable();
    54   ~SuperObservable();
     56  virtual ~SuperObservable();
    5557
    5658  void changeMethod();
     
    6264public:
    6365  NotificationObservable();
    64   ~NotificationObservable();
     66  virtual ~NotificationObservable();
     67
     68  enum NotificationType {
     69    Operation1Notify = 0,
     70    Operation2Notify = 1
     71  };
    6572
    6673  void operation1();
    6774  void operation2();
    68 
    69   Notification_ptr notification1;
    70   Notification_ptr notification2;
    7175};
    7276
     
    7478public:
    7579  NotificationObserver(Notification_ptr notification);
     80  virtual ~NotificationObserver();
    7681
    7782  void update(Observable*);
     
    9196
    9297  ObservableSet(int _num);
    93   ~ObservableSet();
     98  virtual ~ObservableSet();
    9499
    95100  iterator begin();
     
    109114
    110115  ObservableMap(int _num);
    111   ~ObservableMap();
     116  virtual ~ObservableMap();
    112117
    113118  iterator begin();
Note: See TracChangeset for help on using the changeset viewer.