home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.software-eng
- Path: sparky!uunet!destroyer!cs.ubc.ca!mprgate.mpr.ca!lichen!janzen
- From: janzen@lichen.mpr.ca (Martin Janzen)
- Subject: Re: metamodels, metalanguages, templates, domain models ...
- Message-ID: <1992Dec16.210734.16557@mprgate.mpr.ca>
- Sender: janzen@lichen (Martin Janzen)
- Reply-To: janzen@mprgate.mpr.ca
- Organization: MPR Teltech Ltd.
- References: <1992Dec13.203011.24702@sojurn.lns.pa.us> <1992Dec15.191917.1072@mprgate.mpr.ca> <1992Dec16.001309.593@ide.com>
- Date: Wed, 16 Dec 92 21:07:34 GMT
- Lines: 58
-
- In article <1992Dec16.001309.593@ide.com>, biesty@ide.com (Bill Biesty) writes:
- >In article <1992Dec15.191917.1072@mprgate.mpr.ca> janzen@mprgate.mpr.ca writes:
- >[...]
- >>6) mixin classes
- >
- >I've never heard of this one. Could someone fill me in?
-
- Sure! A "mixin" class is one that's intended to be used as a base
- class in order to add particular abilities to its derived classes.
- In other words, you "mix in" the new abilities into the derived classes.
- Using multiple inheritance, you can create some pretty sophisticated
- derived classes simply by combining several mixin base classes.
-
- For example, in order to implement the Model-View-Controller paradigm,
- you could create a "Model" mixin, which adds to a derived class the
- ability to maintain a list of Views, and to notify the Views that they
- are to update themselves. In C++, it might look something like this:
-
- class Model
- {
- public:
- virtual ~Model();
- virtual void attachView(View *);
- virtual void detachView(View *);
- virtual void updateViews(void) const;
- protected:
- Model(void);
- private:
- View ** _view_list;
- unsigned int _num_views;
- unsigned int _alloc_views;
- };
-
- Similarly, a View mixin adds to a derived class the ability to attach
- itself to a (subclass of) Model, and to receive update notifications
- whenever its associated model has changed:
-
- class View
- {
- public:
- virtual ~View();
- virtual void updateView(void) = 0;
- protected:
- View(Model &);
- private:
- Model &_model;
- };
-
- Of course, you now have to provide some useful updateView() behaviour
- specific to your derived class.
-
- For more examples, take a look at the design of the Eiffel libraries.
-
- --
- Martin Janzen janzen@mprgate.mpr.ca (134.87.131.13)
- MPR Teltech Ltd. Phone: (604) 293-5309
- 8999 Nelson Way Fax: (604) 293-6100
- Burnaby, BC, CANADA V5A 4B5
-