good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Stripping bad entries from a constructorby jynx (Priest) |
on Jan 19, 2001 at 05:59 UTC ( [id://52909]=CUFP: print w/replies, xml ) | Need Help?? |
One of the issues that Object-Oriented programming has blessed us with is data encapsulation. For the most part it's a boon. Unfortunately, If you look at some of the standard code out there that gets used in Objects in Perl, people have the ability to assign things to objects that have no business being there.
When i wrote this originally it was to make a fine distinction between calling an Object's accessor method and calling the item explicitly. What i did was set up the object so that all the items (in a hash) had a leading underscore; no big deal. My accessor methods have no leading underscore, thus the distinction. But rather than force people to use a leading underscore, i wanted to make the underscore optional. So i came up with the following (both versions). Later i realized this is a good practice (IMHO) just so that people don't add things to your object hil-nil. i've been using it ever since... jynx
pps Sorry if there's bad formatting, there's no preview button in the Snippets Section!!!
Back to
Cool Uses for Perl
|
|