I will offer this final piece of advise. Encapsulation is always your friend. Many would disagree, but my experience affirms this truth. Whether or not it is trivial encapsulation, it will save you from unforeseen headaches %99.9999 of the time. If you use the encapsulation that you've built within your object instead of direct member access, you can take advantage of the encapsulation within as without. Remember the goal of OOP is to bundle data with behavior, so that the rest of your code doesn't have to know the details. OOP is not just some convenient function access technique. Perl does lots of things well, but I think that it helps teach and propagate bad OOP habits. Some have argued here that creating
trivial accessors/mutators is no different than making them public. Logically that is true, however, the difference will be seen on the maintenance side. If you start setting and getting values via the member variables (a.k.a attributes) now, sure they may be static, but now you have code spattered around that are using the members directly, and when the time comes that you want to update a persistence store, or calculate some value before presentation or persistence, you have a lot more code to change when you compare it with no code changes. I guess if it's a 5 line script that's not too bad, but if so why use objects? Remember objects aren't data structures, they're state machines. Would you want to cross wires just to change the channel on your tv? No, you want to use the remote. You want those
attributes of managing the tv to be
abstracted away from you. Then when you get a new tv, sure there might be more buttons, but the interface is the same.
And in the "For What It's worth" department, the
$obj->get("SomeKey");
$obj->set("SomeKey", "some val");
Notation makes me cringe, IMHO no encapsulation is better than that.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.