Now here is where I'm confused: Why do you need a different method for each bit of data? The first thought in my mind after reading the class::accessor documention was why not do something like this:
$myObject->getValue("myDataField"); $myObject->setValue("myDataField","New Data");
Frankly you don't need to and your second set value is perfectly valid. For instance, if you are working with a custom Date object, having a setMonth, setYear and setDateOfMonth would be invaluable, but for convenience, it be great to have something like, setDate($year,$month,$day). The less typing you do, the less chance of a bug, right?

Also, if you want to make sure that two values which are tightly related and have some sorta dependency on each other, it's less-end-developer-error-prone to put the two together. For instance, if you have an interface for configuring network cards, having a setIp and setHostmask would cause less headache, since assuming a hostmask may be bad (in your eyes).

Finally, sometimes it's a requirement that they both get done. Having something like a prepared sql statement and setting the placeholders, it'd be bad design to do $sth->bind_param($p_num) and then $sth->bind_param($bind_value). Allowing one to get done w/o the other (if they existed) would be an error. $sth->bind_param($p_num, $bind_value) is an example of one that makes perfect sense to do as a dual parameter set. And binding the same parameter twice would be a strange thing to do.

The only time you shouldn't do a mass-set $object->setALotOf Values is either...
.. for convenience, where a pattern of sets occurs over and over again
.. for preventing certain patterns, since though they can be done, it'd just be silly
.. for preventing one thing from happening w/o the other since one acts upon the other and can't be seperated


Play that funky music white boy..

In reply to Re: OO Getters/Setters by exussum0
in thread OO Getters/Setters by theAcolyte

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.