I'd certainly wouldn't use constructors to set attributes. If you do that,
it becomes harder to do inheritance. How would you do multiple inheritance
if your contructors set attributes? Suppose you inherit two classes,
and the constructors of both classes set attributes. At least one of
the constructors will work will not have the right reference to work with.
I also shy away from using lvalued accessors. They are great for examples,
as they don't take much space (screen space is a commodity when presenting),
but they are awkward in practise. You can't easily intercept the passed in
value, so masking such a method is hard.
You don't have to have set_x, get_x accessors -
a common way is to have a single accessors that sets an attribute if
it gets an argument, and gets it if there isn't one.
But I'm not a big users of accessors. For me, objects are more than a
bunch of values with a ribbon around them. If I want just a bunch of
attributes, I'd use something struct-like - for instance, a hash.
For me, an object is a thing that keeps state. Attributes are used to
record the state; methods are used to transit from one state to another.
Abigail
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.