[Nipy-devel] Axis and friends
Tim Leslie
tim.leslie at gmail.com
Sat Jul 8 08:48:25 CDT 2006
Hi All,
I was looking at reference/axis.py today and thinking about the class
structure. At present, we have Axis, which just has a name, then we
derive from the VoxelAxis, which also has a length and a set of
values(), we then derive RegularAxis which adds a start and step
parameter. In essence, we are creating subclasses to _extend_ the base
class. We start off with the bare bones Axis class and add on the new
features at each level.
The other way to approach this design is to have the base class (Axis)
provide the full interface (values, length, name) and then have each
of the base classes _specialise_ this class. So an Axis can have any
set of values it wants, a RegularAxis has values which are regularly
spaced with a given start and step, and a VoxelAxis is a RegularAxis
where start = 0 and step = 1.
The advantages to this kind of arrangement is that there is a single
interface which the external users have to know about, and the
implementation of each of these classes becomes easier.
I've implemented this different arrangement to show what I mean. I was
hoping to hear other peoples thoughts on this design choice. My new
version of axis.py passes all the tests, so we don't have to worry
about breaking existing. The new version cuts the line count from 114
down to 81 and IMHO is a lot easier to read.
What do other people think?
Cheers,
Tim
-------------- next part --------------
A non-text attachment was scrubbed...
Name: axis.py
Type: text/x-python
Size: 2489 bytes
Desc: not available
Url : http://projects.scipy.org/pipermail/nipy-devel/attachments/20060708/2d19ca9a/attachment.py
More information about the Nipy-devel
mailing list