![]() |
|
"be consistent" | |
PerlMonks |
Re: Re: Where/When is OO useful?by Petruchio (Vicar) |
on Jun 25, 2002 at 04:00 UTC ( #177024=note: print w/replies, xml ) | Need Help?? |
Where are you going to store your instance data? Since you asked... in a variable outside the object itself: a closure, in all likelihood. In my experience, this is the best use for flyweight objects in Perl, far better than as an awkward method of strong encapsulation. Here is how I'd do it:
Likely you have your own solution; if it is significantly different (or especially if it's better) than mine, do share it. This solution passes the tests you mentioned, and has become a regular habit for me. I agree with your point: Perl doesn't make it easy to use inheritance. This is a wordy, tiresome ritual, and thus is error-prone. Various aspects of Perl's OO require such rituals, however; personally, I wouldn't single out inheritance on this account. Update: Changed $p's ERA to something realistic, upon zdog's advice. Update: Simplified my code, upon tye's advice. My inclusion of needless code was a cargo-cult imitation of my own practices, which reflected the needs of prior projects. This, I think, underscores my point about the unfortunate effects of rituals which compensate for the shortcomings of a language.
In Section
Meditations
|
|