home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!rational.com!thor!rmartin
- From: rmartin@thor.Rational.COM (Bob Martin)
- Subject: Re: Wanted: Real Example of MI
- Message-ID: <rmartin.722285227@thor>
- Sender: news@rational.com
- Organization: Rational
- References: <1992Nov19.101210.1@happy.colorado.edu>
- Date: Fri, 20 Nov 1992 18:47:07 GMT
- Lines: 32
-
- Here is a "real" example which uses MI. It can, of course, be
- implemented in other ways using SI, but the MI approach has certain
- benefits.
-
- class Shape { public: void Draw()=0 };
- class Point : public Shape {public: void Draw(); private: int x,y;};
- class Line : public Shape {public: void Draw(); private: Point *p1, *p2;};
-
- class NamedObject {public: void SetName(char*); private: char* itsName;};
-
- class NamedPoint: public Point, public NamedObject {public: void Draw();};
- class NamedLine : public Line, public NamedObject {public: void Draw();};
-
- Quite a few member functions have been omitted for the sake of
- brevity. The design should be clear. There exist classes of objects
- which are shapes, and classes of objects which have names. There is a
- certain interface common to all shapes and another which is common to
- all objects with names. Some shapes can also have names, and so they
- should inherit both interfaces.
-
- While this example is quite simple, it shows one of the real-world
- benefits of MI. NamedPoint and NamedLine objects can be used in any
- context which requires either a Shape or a NamedObject.
-
- Also, a NamedObject does not have to be a Shape. Other kinds of
- objects can be give names and can inherit the NamedObject interface.
-
- --
- Robert Martin Training courses offered in:
- R. C. M. Consulting Object Oriented Analysis
- 2080 Cranbrook Rd. Object Oriented Design
- Green Oaks, Il 60048 (708) 918-1004 C++
-