home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!hela.iti.org!usc!ucla-cs!rowley
- From: rowley@base.cs.ucla.edu (Michael T Rowley)
- Subject: Inheriting from cooperating classes (was: HELP : Array of objects...)
- Message-ID: <rowley.728165610@base.cs.ucla.edu>
- Sender: usenet@cs.ucla.edu (Mr Usenet)
- Nntp-Posting-Host: bath.cs.ucla.edu
- Organization: UCLA, Computer Science Department
- Date: 27 Jan 93 20:13:30 GMT
- Lines: 59
-
- The discussion of mixed lists brought to mind an issue that I have
- recently been struggling with.
-
- nikki@trmphrst.demon.co.uk (Nikki Locke) writes:
-
- >In article <mcampbel.727881449@eola.cs.ucf.edu> mcampbel@cs.ucf.edu (Mike Campbell ) writes:
- >>
- >> I agree with your analysis of the problem re: subclasses, however, what if
- >> you buy/purchase/steal classes from multiple vendors/coworkers/victims ?
- >> They necessarily will not have a common base class. (Or is this correctly
- >> deemed "superclass?")
-
- >So miltiply derive from the vendors class and from a common base class of
- >your own.
-
- This works fine unless you have cooperating classes. I came across
- this problem in some parsing classes, but a more familiar example
- would be a LIST class, which uses a LIST_ELEMENT class. Assume these
- classes are distributed without source, and that, for some reason, you
- want to modify the LIST_ELEMENT class.
-
- OO marketing says that if you want to create a class that is just an
- extension of an existing library class, all you have to do is inherit
- from it and make your extensions in the derived (child, sub) class.
-
- 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.
-
- In the system I was working on, I had source to the library classes,
- so I changed the class name of LIST_ELEMENT to LIBRARY_CLASS_ELEMENT,
- then made a new class called LIST_ELEMENT which inherited from the
- original version. This way my modified class was used by the other
- library classes.
-
- If I didn't have the source, what could I have done?
-
- I can think of two mechanism which could solve this problem:
-
- 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.
-
- 2) Allow for the creation of new _parent_ classes for existing
- classes. The new parent would include an explicit listing of children
- (the children then don't have to declare the parent). Thus the
- extensions get inserted into the desired class. Any member functions
- that the new parent needs to use from its child can be declared as
- deferred functions. Unfortunately, this does not allow for redefining
- functions from the library class, only adding new functions.
-
- Any other ideas?
-
- Michael Rowley
- rowley@cs.ucla.edu
-