[Israel.pm] Design Question

Shmuel Fomberg semuelf at 012.net.il
Tue Nov 18 12:35:34 PST 2008


Hi All.

I need a design advice on my module, Data::ParseBinary.

The module works in the Composite design pattern, which means that all 
the classes inherent from one base class "base", and each object may 
have zero or more "children".
The base class defines two methods, build and destroy, and each 
sub-class must implement them, optionally calling the same method in 
it's children, if exists and if it decides to.

The current operation is pretty naive, that the program calls the root 
object, and it calls it's children's methods and so on.

The problem is that this design is not flexible. what if I want to print 
a debug message before and after every object in the hierarchy? What if 
I want to also print what each action returned?

After a talk with Shlomo, I'm thinking about modifying the system to 
iterator-style, where the iterator will traverse the object tree, and 
each object will queue it's children in the iterator.

What do you think? How would you do it?

Shmuel.



More information about the Perl mailing list