[Tutor] design of Point class

Alan Gauld alan.gauld at btinternet.com
Thu Aug 26 01:10:03 CEST 2010


"Gregory, Matthew" <matt.gregory at oregonstate.edu> wrote

>.  It seems like coding the Point class with multiple distance 
>methods
> is not very flexible, especially if you wanted to iterate over those 
> methods
> for any two points

Its flexible enough provided you keep the interface to points. In 
other words
if the distance is expressed as the difference between two points that 
can
be worked out regardless of representation. The trick is to always 
keep the
interface as free of internal representation detail as possible.

However, you may not be able to provide concrete implementations of
those methods at the level of Point - which means Point turns into an
abstract class. Alternatively you may implement the methods in such
way that they call still other methods to perform data conversions
(polar-cartesian say) or generate default  values where none exist
- generating an X,Y from a list of dimensions maybe. And the Point
class implementation of those conversions may be trivial.

There are seveal ways to do this and none of them are perfect and none
of them are "right" - although a few of them might be considered 
"wrong"!.

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list