home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / cplus / 15839 < prev    next >
Encoding:
Text File  |  1992-11-06  |  2.0 KB  |  46 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!charon.amdahl.com!pacbell.com!decwrl!sdd.hp.com!caen!sol.ctr.columbia.edu!The-Star.honeywell.com!umn.edu!mmm.serc.3m.com!pwcs!cdsmn!wells
  3. From: wells@cdsmn.mn.org (Rich Wells)
  4. Subject: Re: Const Inheritance
  5. Message-ID: <Bx970t.B72@cdsmn.mn.org>
  6. Organization: Dicomed, Inc
  7. X-Newsreader: TIN [version 1.1 PL6]
  8. References: <2762@devnull.mpd.tandem.com>
  9. Date: Thu, 5 Nov 1992 17:24:28 GMT
  10. Lines: 34
  11.  
  12. Duane Voth (duanev@devnull.mpd.tandem.com) wrote:
  13. : frank@Cookie.secapl.com (Frank Adams) writes:
  14. : >The idea comes from one of the standard examples of an inheritance
  15. : >hierarchy: shapes.  Assume we have a class Shape, with a subclass
  16. : >Rectangle, and we want to add Square as a class.  It seems logical that
  17. : >Square should be a subclass of Rectangle.
  18.  
  19. Let us not confuse "subset" with "subclass".  "Subclass" is a concept
  20. we use for implementation; it need not correspond directly to the
  21. "subset" and "superset" concepts we may be modeling.
  22.  
  23. So: although the set of squares is a subset of the set of rectangles,
  24. it does not (necessarily) mean that the class "square" should be a
  25. subset of class "rectangle".  Inheritance can be used for both
  26. genericity AND specialization.  In this case, perhaps Square may be
  27. the immediate subclass of Shape, with Rectangle a more generic
  28. subclass of Square containing an extra field for the extra degree
  29. of freedom.
  30.  
  31. Of course, this leaves us with objects of type Square * which point
  32. to objects which violate the basic tenets of Squaredom, which is that
  33. all 4 sides are equal.  Therefore....
  34.  
  35. : Perhaps the common mathematical definition of a square has led to
  36. : this delema.  Sounds as if, in this instance, there are more differences
  37. : between a square and a rectangle than there are similarities.
  38. : Would making class Square and class Rectangle peers of each other
  39. : cause so much duplication that the simplicity is unwaranted?
  40.  
  41. No.  That is, Yes they may as well be peers.  The differences far
  42. outweigh the similarities.
  43. -- 
  44.  
  45. Richard Wells  wells@cdsmn.mn.org  or  ...!tcnet!cdsmn!wells
  46.