home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / cplus / 19686 < prev    next >
Encoding:
Text File  |  1993-01-21  |  2.7 KB  |  64 lines

  1. Xref: sparky comp.lang.c++:19686 comp.object:4976
  2. Newsgroups: comp.lang.c++,comp.object
  3. Path: sparky!uunet!cs.utexas.edu!sdd.hp.com!saimiri.primate.wisc.edu!doug.cae.wisc.edu!zazen!schaefer.math.wisc.edu!wayne
  4. From: wayne@schaefer.math.wisc.edu (Rick Wayne)
  5. Subject: need help with OO design question, or "What's My Hierarchy?"
  6. Message-ID: <1993Jan21.035951.8331@schaefer.math.wisc.edu>
  7. Organization: Univ. of Wisconsin Dept. of Mathematics
  8. Date: Thu, 21 Jan 93 03:59:51 GMT
  9. Lines: 53
  10.  
  11.  
  12.  
  13. hello all, i have a question for you object.experts.  i'm involved in 
  14. the design of an app which we╒re going to implement in BC++ 3.1 TVision.
  15. i'm having a hard time coming up with a solution that's elegant.  please
  16. bear with me if you think "but that's *obvious*", put it down to my
  17. inexperience.
  18.  
  19. our app deals with documents.  there are several kinds of documents,
  20. doc1, doc2, and doc3.  each kind of document shares many behaviors and
  21. features (e.g. output as ASCII).
  22.  
  23. documents are made up of sections.  sections can be of several different
  24. types, like ID, Module, and Stats.  sections also share a lot of 
  25. behavior, for instance they too need to be able to represent 
  26. themselves as ASCII on a stream.
  27.  
  28. let's say that doc1s have just ID, doc2s have ID and Stats, and doc3s 
  29. have ID, Module(s), and Stats.
  30.  
  31. so far, so good.  Document is an abstract superclass, with as much 
  32. behavior as i can find in common.  doc1, doc2, and doc3 are subclasses.
  33. Section is another abstract superclass, with ID, Module, and Stats 
  34. deriving from it.
  35.  
  36. question 1: an obvious way to implement, say, doc3, is to define it with
  37. members ID, Module, and Stat.  however, every time i want to have the 
  38. whole Document write itself out to ASCII, i have to say
  39.  
  40.     mydoc3.ID.ascout();
  41.     mydoc3.Module.ascout();
  42.     mydoc3.Stat.ascout();
  43.  
  44. or some such.  i also have to repeat this for each Document subclass.
  45. is there a clean way to use a container class here instead of defining 
  46. the sections as members, and just have document-wide methods iterate 
  47. over the contents of the container?
  48.  
  49. question 2: notice that IDs are common to all documents.  they could
  50. therefore be part of Document, instead of doc1, doc2, and doc3, right?
  51. on the other hand, ID Sections in doc2s have to have behavior that's 
  52. just *slightly* different.  unfortunately, if the ID is part of 
  53. Document, i'm stuck with the generic version -- right?  you can override 
  54. a method inherited from a superclass, but not a method contained in a
  55. *member* inherited from a superclass, nor can you override the member
  56. itself (i.e. i'd love to override the inherited member ID with myID).
  57.  
  58. final question: is that last point a desirable language feature?
  59.  
  60.  
  61. rick
  62.  
  63. (please direct email replies to wayne@express.uwex.edu -- thanks!)
  64.