in reply to Re: Class attribute get/set approach flaws?
in thread Class attribute get/set approach flaws?
If the methods are never going to do anything but get or set the object's values, they're probably superfluous and add needless complexity, which is usually a bad thing; in that case, it's probably better to let the calling code get or set the variables via normal assignment.
This is not likely to be a popular stance around here.
I don't entirely disagree... This is useful for some very simple classes which are just glorified hashes anyway and, preferably, are used only in one application.
But, you should recognize that there is a huge problem with this approach. It locks you into an implementation. Say you want to change your hash-based objects into "inside-out objects" down the road, for instance. You've got to change all the code that uses your class. If your class has gotten any real use, that's probably not going to be an easy task.
So, unless you're pretty damn sure you're never going to change the implementation of your class, you don't want to do this.
And, really, who's ever that sure?
-sauoq "My two cents aren't worth a dime.";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Class attribute get/set approach flaws?
by jonadab (Parson) on Nov 29, 2005 at 05:05 UTC |