Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
Re: Seeking advice for OO-related strategyby mstone (Deacon) |
on Mar 05, 2005 at 22:44 UTC ( [id://436967]=note: print w/replies, xml ) | Need Help?? |
Any alternative suggestion? How is this kind of things generally done? It's usually cleaner to demote the object's data to a separate class owned by the parent object, or even just to a single data structure owned by the parent object: Instead of this:
do this:
By demoting the data, you get rid of the circular dependency between the parent object and the user-supplied child function. The child function doesn't need to know anything at all about the parent object, it only needs to know the data object, or hash, or whatever. Instead of calling your child functions like so:
You can just pass the data:
It may not look like that big a change, but it gets rid of chicken-and-the-egg problems that can drive you absolutely nuts at design time.
In Section
Seekers of Perl Wisdom
|
|