home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.lang.c++:19686 comp.object:4976
- Newsgroups: comp.lang.c++,comp.object
- Path: sparky!uunet!cs.utexas.edu!sdd.hp.com!saimiri.primate.wisc.edu!doug.cae.wisc.edu!zazen!schaefer.math.wisc.edu!wayne
- From: wayne@schaefer.math.wisc.edu (Rick Wayne)
- Subject: need help with OO design question, or "What's My Hierarchy?"
- Message-ID: <1993Jan21.035951.8331@schaefer.math.wisc.edu>
- Organization: Univ. of Wisconsin Dept. of Mathematics
- Date: Thu, 21 Jan 93 03:59:51 GMT
- Lines: 53
-
-
-
- hello all, i have a question for you object.experts. i'm involved in
- the design of an app which we╒re going to implement in BC++ 3.1 TVision.
- i'm having a hard time coming up with a solution that's elegant. please
- bear with me if you think "but that's *obvious*", put it down to my
- inexperience.
-
- our app deals with documents. there are several kinds of documents,
- doc1, doc2, and doc3. each kind of document shares many behaviors and
- features (e.g. output as ASCII).
-
- documents are made up of sections. sections can be of several different
- types, like ID, Module, and Stats. sections also share a lot of
- behavior, for instance they too need to be able to represent
- themselves as ASCII on a stream.
-
- let's say that doc1s have just ID, doc2s have ID and Stats, and doc3s
- have ID, Module(s), and Stats.
-
- so far, so good. Document is an abstract superclass, with as much
- behavior as i can find in common. doc1, doc2, and doc3 are subclasses.
- Section is another abstract superclass, with ID, Module, and Stats
- deriving from it.
-
- question 1: an obvious way to implement, say, doc3, is to define it with
- members ID, Module, and Stat. however, every time i want to have the
- whole Document write itself out to ASCII, i have to say
-
- mydoc3.ID.ascout();
- mydoc3.Module.ascout();
- mydoc3.Stat.ascout();
-
- or some such. i also have to repeat this for each Document subclass.
- is there a clean way to use a container class here instead of defining
- the sections as members, and just have document-wide methods iterate
- over the contents of the container?
-
- question 2: notice that IDs are common to all documents. they could
- therefore be part of Document, instead of doc1, doc2, and doc3, right?
- on the other hand, ID Sections in doc2s have to have behavior that's
- just *slightly* different. unfortunately, if the ID is part of
- Document, i'm stuck with the generic version -- right? you can override
- a method inherited from a superclass, but not a method contained in a
- *member* inherited from a superclass, nor can you override the member
- itself (i.e. i'd love to override the inherited member ID with myID).
-
- final question: is that last point a desirable language feature?
-
-
- rick
-
- (please direct email replies to wayne@express.uwex.edu -- thanks!)
-