The MV(C) paradigm: the model class

This demonstates a Model/View example based on a simple counter. See "Principles of Object-Oriented Sostware Development" by Anton Eliens, page 237.

jrvosse@cs.vu.nl
  #ifndef _MODEL_H_
  #define _MODEL_H_

  #include<hush/kit.h>
  #include<hush/event.h>
  #include<hush/handler.h>

  typedef handler model;

  class counter: public model {   
  public:
    counter(int i=0): _value(i) { change(); }

    int operator++() { ++_value; change(); return value(); }

    int value() const { return _value; }

  protected:
    void change() {
      // Create event to notify dependents of change :
      int argc = 1; char* argv[] = { "counter", 0 };
      event *e = new event(tk,argc,argv);
      process(e);
      delete e;
    }

  private:
    int _value;
  };

  #endif