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: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?$myObject->getValue("myDataField"); $myObject->setValue("myDataField","New Data");
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
In reply to Re: OO Getters/Setters
by exussum0
in thread OO Getters/Setters
by theAcolyte
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |