OO design
Florian Diesch
diesch at spamfence.net
Wed Jul 20 11:27:05 EDT 2005
chris <cf_1957 at hotmail.com> wrote:
> I've been scripting with python for a while now. Basically writing a few
> functions and running in the ipython shell. That's been very useful. But the
> more I do this the more I see that I'm doing more or less the same thing
> over and over again. So its feels like I need to get into class programming
> with all its attendant benefits. However my biggest problem is a conceptual
> one. I just can't get my head around defining suitable classes, how they
> aquire data and communicate with each other. I'm hoping some of you python
> lamas out there might be able to share some of your wisdom on the subject.
Just some thoughts about it:
> What I basically do is a lot of the following::
>
> 1. get arbitrary numerical data (typically large data sets in columnar
> format or even via COM from other packages. I generally have to deal with
> one or more sets of X,Y data)
You may create a class for each data format that reads that data and
creates a set from it.
> 2. manipulate the data (scaling, least squares fitting, means, peaks,
> add/subtract one XY set from another etc)
This methods may either manipulate youe set's data or create a new set
with the data
> 3. plot data (original set, results of manipulation, scatterplot, histograms
> etc - I use matplotlib)
I never useds matplotlib. Maybe it's usefull to have one or more classes
covering the functions you need.
> 4. export data (print, csv, shelve)
Again have a class for each output format.
> I have no problem writing bits of functional code to do any of the above.
> But for the life of me I can't see how I can hook them altogether in an OO
> based framework that I can build and extend (with more data formats,
> manipulations, GUI etc).
>
> When I think about what I should do I end up with a class XY that has a
> method for everything I want to do eg.
>
> class XY:
> def read_file
> def scale_data
> def plot_data
> def shelve_data
>
> But somehow that doesn't feel right, especially when I expect the number of
> methods will grow and grow, which would make the class very unwieldy.
>
> Even if that was a legitimate option, I don't understand conceptualy how I
> would, for example, plot two different XY objects on the same graph or add
> them together point by point. How do two different XY objects communicate
Have a look at the IntervalSet module someone announced here some time
before to get some ideas.
> and how do you deal with the thing that they must have in common (the plot
> screen for example).
Create classes for this things. Then you may either pass XY to method of Thing
or the Thing to a method of XY.
Florian
--
begin signature_virus
Hi! I'm a signature virus. Please copy me to your signature to help me spread.
end
More information about the Python-list
mailing list