Beginner question: module organisation

Rainer Grimm r.grimm at science-computing.de
Sat May 19 11:33:51 EDT 2007


Mail.To.Nathaniel at gmail.com wrote:
> Hello :)
> 
> I am new to python and I don't have much expirience in object-oriented
> technologies neither.
> 
> The problem is the following: I have to create a simple python
> template script that will always follow the same algorithm, let's say:
> - read a mesh
> - transform the mesh (let's say, refine)
> 
> The last step should be a kind of a black box:
> - the same input data format
> - some algorithme inside
> - the same output data format
> 
> A number of different refine methods should be implemented. The end-
> user must be able to write easily a new method and call it from the
> base script without any major change.
> 
> Something like this would be a solution (no classes created, no OO
> programming):
> - a module defining REFINE1(mesh), REFINE2(mesh), ...
> - in the script:
>   from MODULE import REFINE2 as REFINE
>   REFINE(mesh)
> 
> Is it a proper solution for this kind of problem? How would you
> implement this kind of task?
> 
Hello.

Have a look at the classical GangOfFour design pattern book. You can 
especially with the template methode design the processing of your data. 
The strategy pattern will help you to vary the algroithm in your processing.

To be concret, in your base class you define the processing of the data. 
  There are two distinct methods to do it.
delegate the variation of the algorithmns to other objects => strategy 
pattern
override the steps of the processing in subclasses => template method

Regards,
Rainer
-- 
  _________________________creating IT solutions
Rainer Grimm
scVENUS Schulungsleiter                     science + computing ag
phone   +49(0)7071 9457-253                 Hagellocher Weg 73
fax     +49(0)7071 9457-511                 D-72070 Tuebingen, Germany
r.grimm at science-computing.de                www.science-computing.de



More information about the Python-list mailing list