Saifi's Suggestions

Saifi has sent to me three suggestions of how the inheritance graph of the classes DrawableObject, Point, Circle, Rectangle, 3D-Point and Sphere might look like.

I'd like to present some comments and two additional suggestions. But first, after discussing these suggestions with some of my colleagues we came up to the opinion that there is no right answer. The answer highly depends on the environment in which the objects (of these classes) should be used. Consequently, the environmental settings usually urge a specific inheritance graph.

Figure 1 shows Saifi's first suggestion. Here, Sphere is derived from both 3D-Point and Circle. With our discussion about multiple inheritance, this solution makes only sense if Point is derived only once. It should not result in an inheritance relationship in which a Sphere object has two copies of Point instances. Otherwise there would be no unique reference point.

  figure22
Figure 1:  First version of inheritance graph.

Let's refer to an inheritance scheme in which Point instances would only exist once in an object of a multiply derived class as virtual. However, if class Sphere is virtually derived from Point why not also derive Cuboid from Rectangle (and thus virtually from Point)? Saifi's third suggestion shown in Figurer 2 does exactly that.

  figure36
Figure 2:  Second version of inheritance graph.

The third (and Saifi's second suggestion) is a little bit strange, because Sphere inherits directly from Circle (Figure 3). This would require Sphere to add a coordinate for the third dimension. Consequently, there would be no identifiable reference point! Its coordinates would be distributed across Circle and Sphere. And this would not enable us to uniquely reference a Sphere as we could with the other objects.

  figure47
Figure 3:  Third version of inheritance graph.



P. Mueller
Wed May 14 10:31:40 MST 1997