home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / software / 5018 < prev    next >
Encoding:
Text File  |  1992-12-16  |  2.4 KB  |  71 lines

  1. Newsgroups: comp.software-eng
  2. Path: sparky!uunet!destroyer!cs.ubc.ca!mprgate.mpr.ca!lichen!janzen
  3. From: janzen@lichen.mpr.ca (Martin Janzen)
  4. Subject: Re: metamodels, metalanguages, templates, domain models ...
  5. Message-ID: <1992Dec16.210734.16557@mprgate.mpr.ca>
  6. Sender: janzen@lichen (Martin Janzen)
  7. Reply-To: janzen@mprgate.mpr.ca
  8. Organization: MPR Teltech Ltd.
  9. References: <1992Dec13.203011.24702@sojurn.lns.pa.us> <1992Dec15.191917.1072@mprgate.mpr.ca> <1992Dec16.001309.593@ide.com>
  10. Date: Wed, 16 Dec 92 21:07:34 GMT
  11. Lines: 58
  12.  
  13. In article <1992Dec16.001309.593@ide.com>, biesty@ide.com (Bill Biesty) writes:
  14. >In article <1992Dec15.191917.1072@mprgate.mpr.ca> janzen@mprgate.mpr.ca writes:
  15. >[...]
  16. >>6) mixin classes
  17. >
  18. >I've never heard of this one. Could someone fill me in?
  19.  
  20. Sure!  A "mixin" class is one that's intended to be used as a base
  21. class in order to add particular abilities to its derived classes.
  22. In other words, you "mix in" the new abilities into the derived classes.
  23. Using multiple inheritance, you can create some pretty sophisticated
  24. derived classes simply by combining several mixin base classes.
  25.  
  26. For example, in order to implement the Model-View-Controller paradigm,
  27. you could create a "Model" mixin, which adds to a derived class the
  28. ability to maintain a list of Views, and to notify the Views that they
  29. are to update themselves.  In C++, it might look something like this:
  30.  
  31.     class Model
  32.     {
  33.       public:
  34.     virtual ~Model();
  35.     virtual void attachView(View *);
  36.     virtual void detachView(View *);
  37.     virtual void updateViews(void) const;
  38.       protected:
  39.     Model(void);
  40.       private:
  41.     View **       _view_list;
  42.     unsigned int  _num_views;
  43.     unsigned int  _alloc_views;
  44.     };
  45.  
  46. Similarly, a View mixin adds to a derived class the ability to attach
  47. itself to a (subclass of) Model, and to receive update notifications
  48. whenever its associated model has changed:
  49.  
  50.     class View
  51.     {
  52.       public:
  53.     virtual ~View();
  54.     virtual void updateView(void) = 0;
  55.       protected:
  56.     View(Model &);
  57.       private:
  58.     Model &_model;
  59.     };
  60.  
  61. Of course, you now have to provide some useful updateView() behaviour
  62. specific to your derived class.
  63.  
  64. For more examples, take a look at the design of the Eiffel libraries.
  65.  
  66. -- 
  67. Martin Janzen                     janzen@mprgate.mpr.ca (134.87.131.13)
  68. MPR Teltech Ltd.                  Phone: (604) 293-5309
  69. 8999 Nelson Way                   Fax: (604) 293-6100
  70. Burnaby, BC, CANADA  V5A 4B5
  71.