[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: OO should break when broken
On Monday, September 1, 2003, at 04:05 AM, Geoffrey Knauth wrote:
> On Monday, September 1, 2003, at 06:14 AM, Colin Putney wrote:
>> An ellipse is a circle with additional capabilities - it can have
>> different radii along each of its dimensions.
> This reminds me of something that bothers me about OO: the
> accumulation of unused stuff. When I extend Circle to make Ellipse, I
> add x-radius and y-radius, but the original radius instance variable
> is still there. Since I'm not going to use Circle's radius any more,
> I wish I could just ask it to go away, if the compiler or runtime
> could verify it isn't needed by methods I decide not to override.
That's more a naming issue than anything else. There's no need to have
the original radius go unused. Just designate it as being the x-radius
and only add one instance variable for y-radius. With appropriately
named accessor methods, it won't even look funny in the code.
Ultimately, though, I don't think there's much point in having a Circle
class at all, since Ellipse would end up overriding most of its methods
anyway. All you really need is a convenience constructor for creating