With that quick hack, adding a new attribute is as simple as adding a new key/value pair to the validation lookup.
Well, that glosses over the fact that adding the key/value pair might not be easy depending on the validation and/or behavior you need for a given attribute... You might need to write a new validation function, for instance. And, you might want to change the names of things a bit if, for instance, you want functions that don't just perform validation but, say, set other values. (Change the radius and update the area, to use an example that's been used frequently today.)
But, okay. Yeah. Sure. You can do things like that. I've even done it, though not quite like that.
It might even buy you something in the common cases... I'm not sure how much though and I've come to think that just writing a separate method is easy enough and usually neater. So, that's what I usually do these days. (I do prefer accessors that both set and get though.)
-sauoq "My two cents aren't worth a dime.";
In reply to Re^3: Class attribute get/set approach flaws?
by sauoq
in thread Class attribute get/set approach flaws?
by radiantmatrix
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |