home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: cvnet.c++,comp.lang.c++
- Path: sparky!uunet!mcsun!sun4nl!ruuinf!prisma.cv.ruu.nl!rvloon
- From: rvloon@cv.ruu.nl (Ronald van Loon)
- Subject: Real life problem: what is the proper way of subclassing this ?
- Originator: rvloon@triton.cv.ruu.nl
- Sender: usenet@cv.ruu.nl (Usenet Network)
- Message-ID: <1992Nov16.160806.29351@cv.ruu.nl>
- Date: Mon, 16 Nov 1992 16:08:06 GMT
- Nntp-Posting-Host: triton.cv.ruu.nl
- Organization: University of Utrecht, 3D Computer Vision Research Group
- Keywords: OOP,superclass-subclass relationships, real life problem
- Lines: 68
-
- The problem is the following:
-
- consider a basic graphics class, called 'point3d' encapsulating the concept of
- a 3D-point in a coordinate-system. Mind you, the coordinate system is
- important, every point has one. A number of operations are defined on those
- points, like multiplication (inproduct), adding (translation) etc. etc.
- Everytime two points are incompatible, ie. are in different coordinatesystem,
- one of the two is forced in the coordinatesystem by a coordinate
- transformation.
-
- Now, for efficiency reasons, the check whether points are in the same
- coordinatesystem needs to be removed, as it turns out that most of the time
- points are already in the same coordinatesystem, hence testing is not needed.
-
- Two approaches can now be taken:
-
- 1. The original 3-dimensional point in coordinatesystem concept is a special
- case of a normal 3-dimensional point:
-
- class point_3d
- {
- // baseclass
-
- ... operations ...
-
- };
-
- class point_3d_with_coordinate_system
- : public point_3d
- {
- // subclass
- };
-
- additional advantage:
-
- all code for point_3d_with_coordinate_system is very straightforward:
-
- point_3d_wc::function(point_3d& point2)
-
- if (point1 not in same coordinate system as point 2)
- force point2 in same coordinate system as point1
-
- execute equivalent code in baseclass (as coordinate systems are the same)
-
-
- 2. The 3 dimensional point without checks for coordinate systems is a special
- case of the normal case.
-
- class point_3d_with_coordinate_system
- {
- // different baseclass
- };
-
- class point_3d_with_no_coordinate_system_check
- : public point_3d_with_coordinate_system
-
- obvious disadvantage:
-
- all code from the base-class needs to be duplicated (as the code from
- the baseclass contains the check for coordinate systems).
-
- Any and all opinions from the net appreciated
-
- --
- +--- Ronald van Loon ---+
- | (rvloon@cv.ruu.nl) |
- | 3DCV Group, Utrecht |
- +--- The Netherlands ---+ This part of .signature intentionally left blank.
-