Re: Clean Object Class Design -- Circle/Ellipse
Date: Thu, 19 Jul 2001 22:01:58 -0400
Message-ID: <jqM57.178$Ls3.48376865_at_radon.golden.net>
>>>I must admit that I judged the article upon it's ability to answer a set
of
>>>questions I have in mind, which is not quite fair. Here it is:
>>>
>>>1. Is the case Square/Rectangle really similar to Circle/Ellipse?
>>
>>Yes.
>
>Then, why does evaluating Ellipse perimeter requires elliptic integral
knowledge
>but is trivial for Rectangle?
I said it was similar -- not the same.
>>>i. What methods/operations in Rectangle signature would make it different
from
>>>Ellipse?
>>
>>A rectangle, like any quadrilateral, has four vertices. A rectangle, like
>>any polygon, has a property that describes the number of sides.
>
>Why can't we declare that ellipse has infinitely many vertices/sides?
We could. We could also declare that ellipse has zero sides or vertices. It depends on how you define vertex and side. If a side has finite length, then an ellipse has zero sides. If a vertex marks the intersection of two sides of finite length, then an ellipse has zero of those as well.
I see a couple of problems with declaring an infinite number of vertex properties: How are users of the ellipse class going to identify which of the infinite vertices they want to access? How does the computer evaluate a relation valued attribute with an infinite number of tuples?
Even for the property that describes the number of sides, infinite does not obey the rules of mathematics as they apply to real numbers.
In either case, a rectangle has four vertices and an ellipse does not.
>>>If they are identical from signature perspective, then, maybe,
>>>Rectangle and Ellipse are just 2 different implementations of same type?
>>
>>Why would they be identical?
>
>Both could be defined as invariants of cyclic subgroup of octic (dihedral)
group
>of order 4.
If octic groups of order 4 have important meaning to your problem space, you could derive both rectangle and ellipse from such a class. For that matter, they are also both shapes.
That does not mean that they are identical. A rectangle has exactly four properties identifying the location of vertices and an ellipse does not.
>>>ii. Is there a method in Square/Rectangle case that one might want to
override
>>>for performance reasons? It seems to me that we don't need to introduce
Square
>>>type at all.
>>
>>Unless one wants a variable that is a square and must always be a square
for
>>reasons other than performance.
>
>Such as a convenient name? Rectangle with a constraint wouldn't do?
In many cases, a constrained rectangle would do -- perhaps even in all of cases assuming you have some means to constrain your variable. Of course, in the circle/ellipse case, one might require a circle variable or a circle value that has a defined radius. Received on Fri Jul 20 2001 - 04:01:58 CEST