home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16368 < prev    next >
Encoding:
Text File  |  1992-11-16  |  2.5 KB  |  82 lines

  1. Newsgroups: cvnet.c++,comp.lang.c++
  2. Path: sparky!uunet!mcsun!sun4nl!ruuinf!prisma.cv.ruu.nl!rvloon
  3. From: rvloon@cv.ruu.nl (Ronald van Loon)
  4. Subject: Real life problem: what is the proper way of subclassing this ?
  5. Originator: rvloon@triton.cv.ruu.nl
  6. Sender: usenet@cv.ruu.nl (Usenet Network)
  7. Message-ID: <1992Nov16.160806.29351@cv.ruu.nl>
  8. Date: Mon, 16 Nov 1992 16:08:06 GMT
  9. Nntp-Posting-Host: triton.cv.ruu.nl
  10. Organization: University of Utrecht, 3D Computer Vision Research Group
  11. Keywords: OOP,superclass-subclass relationships, real life problem
  12. Lines: 68
  13.  
  14. The problem is the following:
  15.  
  16. consider a basic graphics class, called 'point3d' encapsulating the concept of
  17. a 3D-point in a coordinate-system. Mind you, the coordinate system is
  18. important, every point has one. A number of operations are defined on those
  19. points, like multiplication (inproduct), adding (translation) etc. etc.
  20. Everytime two points are incompatible, ie. are in different coordinatesystem,
  21. one of the two is forced in the coordinatesystem by a coordinate
  22. transformation.
  23.  
  24. Now, for efficiency reasons, the check whether points are in the same
  25. coordinatesystem needs to be removed, as it turns out that most of the time
  26. points are already in the same coordinatesystem, hence testing is not needed.
  27.  
  28. Two approaches can now be taken:
  29.  
  30. 1. The original 3-dimensional point in coordinatesystem concept is a special
  31.    case of a normal 3-dimensional point:
  32.  
  33.    class point_3d
  34.    {
  35.     // baseclass
  36.  
  37.     ... operations ...
  38.  
  39.    };
  40.  
  41.    class point_3d_with_coordinate_system
  42.     : public point_3d
  43.    {
  44.      // subclass
  45.    };
  46.  
  47.    additional advantage:
  48.  
  49.    all code for point_3d_with_coordinate_system is very straightforward:
  50.  
  51.    point_3d_wc::function(point_3d& point2)
  52.  
  53.    if (point1 not in same coordinate system as point 2)
  54.      force point2 in same coordinate system as point1
  55.  
  56.    execute equivalent code in baseclass (as coordinate systems are the same)
  57.  
  58.  
  59. 2. The 3 dimensional point without checks for coordinate systems is a special
  60.    case of the normal case.
  61.  
  62.    class point_3d_with_coordinate_system
  63.    {
  64.      // different baseclass
  65.    };
  66.  
  67.    class point_3d_with_no_coordinate_system_check
  68.     : public point_3d_with_coordinate_system
  69.  
  70.    obvious disadvantage:
  71.  
  72.    all code from the base-class needs to be duplicated (as the code from
  73.    the baseclass contains the check for coordinate systems).
  74.  
  75. Any and all opinions from the net appreciated
  76.  
  77. -- 
  78. +--- Ronald van Loon ---+ 
  79. |  (rvloon@cv.ruu.nl)   | 
  80. |  3DCV Group, Utrecht  |
  81. +--- The Netherlands ---+ This part of .signature intentionally left blank.
  82.