home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!ascent!ascent!eb
- From: eb@ascent.com (Ed Barton)
- Subject: Re: Inheriting from cooperating classes (was: HELP : Array of objects...)
- In-reply-to: rowley@base.cs.ucla.edu's message of 27 Jan 93 20:13:30 GMT
- Message-ID: <EB.93Jan28101151@MountRushmore.ascent.com>
- Date: 28 Jan 93 10:11:51
- References: <rowley.728165610@base.cs.ucla.edu>
- Organization: Ascent Technology, Inc., Cambridge Massachusetts
- Lines: 42
-
- In article <rowley.728165610@base.cs.ucla.edu> rowley@base.cs.ucla.edu (Michael T Rowley) writes:
- ...
- Problem: other classes in the library (e.g. LIST) create instances of
- LIST_ELEMENT. They won't use your new derived class!
-
- I believe this is a problem with any class that has instances created
- by other library classes.
- ...
- I can think of two mechanism which could solve this problem:
-
- [When you are designing a library,]
-
- 1) Never use another class from within a class. Use only constrained
- generic parameters (parameterized types). Thus a generic list class
- would need to be declared LIST[LIST_ELEMENT,MEMBER_TYPE], or, if you
- made a subclass LIST[NEW_LIST_ELEMENT,MEMBER_TYPE]. It's a little
- less ugly if generic parameters could have defaults, as in Sather 1.0.
-
- Any other ideas?
-
- IMO, this is an unnecessarily strong constraint. For the cases where
- the new auxiliary objects are dynamically allocated by the library, I
- would suggest instead that the class (LIST, here) should have a
- virtual function that it uses to create the auxiliary objects, instead
- of using "new" directly. That way, a subclass of LIST can use a
- subtype of LIST_ELEMENT objects if that's what is needed.
-
- (Of course, not every class, and not every auxiliary class, is
- designed for inheritance. The library designer has to think ahead and
- decide whether or not to support inheritance. This discussion is
- therefore confined to the cases where the possibility of subclassing
- is supported. It's a design flaw if subclassing is excluded without
- good reason, of course.)
-
-
-
-
-
-
-
-
-
-