Re: Another OO Problem (and thanks for the input I received so far)

From: Programmer Dude (Chris_at_Sonnack.com)
Date: 11/03/04


Date: Tue, 02 Nov 2004 17:51:18 -0600

TGOS writes:

> An ellipse needs RadiusA and RadiusB. But a circle has only one radius.
> So it would over two getRadius that always yield the same result; so
> there is one too much. This may however be desired, if you want to use a
> cirle as a special kind of ellipse.
>
> On the other hand, a circle could offer getRadius and an ellipse could
> extend it with getAlternateRadius or getSecondRadius.
>
> Both is probably possible...

Indeed. If I did decide that a circle should be a sub-class of ellipse,
I'd inherit and hide the second focal point and radius and add a class
invariant insuring those fields were always the same value.

There are also issues going the second direction. If a circle has a
centerpoint field and a radius field and you inherit circle to ellipse,
which focalpoint inherits circle's centerpoint, and which radius gets
circle's radius?

I might very well do what some paint programs have done and consider
them as distinct classes that both inherit from shape. That is, neither
inherits from the other. For most programming purposes I can think of,
circles and ellipses just aren't that related.



Relevant Pages

  • Re: Please help with elliptical path algorithm
    ... path.push_back* radius, ... Well an ellipse can be considered just a circle, ... A,B are the start and end points; F is the stretch factor (1 is normal ...
    (comp.programming)
  • Re: Find center of ellipse
    ... Suppose to have a circle centered in the origin with radius 'r'. ... you want to find the center of this ellipse when it touches the circle ... Perhaps you mean to require the axes to parallel the ...
    (sci.math)
  • Re: two little angel/degrees graphing questions
    ... > Cos* Radius = X ... parametric equations of the circle. ... Equation of ellipse, centered at with axis along the x and y ...
    (sci.math)
  • Re: Why is OO Popular?
    ... >Also, SetRadiuscan be inherited from circle to ellipse, it ... >has sense for ellipse just like GetSemiAxisB has sense in circle. ... We need to be able chose wich methods to inherit from the supertype. ...
    (comp.object)
  • Re: Composition vs. inheritance
    ... circle is an ellipse where the major and minor axises are fixed to the ... circle is a type of ellipsis it doesn't make sense to use inheritance to ... sometimes you want to inherit behaviour without also ...
    (comp.lang.java.programmer)