If only it were that simple. That article -- which is at once good, contested, and a little out of date-- is making a point about the improper use of getters/setters, mainly in Java. It certainly makes some good points about how to design and use classes. And I think the current consensus is to use getters/setters less often. His previously provocative article was about using composition rather than inheritance -- also often heard advice today.Roja wrote:A quite delicious response was written by someone else to that very concept.Jenk wrote:_ANY_ property in a class is to be set via a setter, and 'get' through a getter imo.
A fundamental precept of OO systems is that an object should not expose any of its implementation details. This way, you can change the implementation without changing the code that uses the object. It follows then that in OO systems you should avoid getter and setter functions since they mostly provide access to implementation details.
But his major point is about Tell, don't ask which is a broad design topic that can be a little subtle if you are not well versed in OOD -- I certainly don't understand it very well. I guess that my problem with "Is Evil" statements is that they usually lack an clear alternative of what to do. That is probably because the poor choice should actually be replaced with several different good choices depending on the circumstance.
I would note that he starts his article with this:
Allen Holub wrote:This column and last month's article are about design. Design, by nature, is a series of trade-offs. Every choice has a good and bad side, and you make your choice in the context of overall criteria defined by necessity. Good and bad are not absolutes, however. A good decision in one context might be bad in another.
If you don't understand both sides of an issue, you cannot make an intelligent choice; in fact, if you don't understand all the ramifications of your actions, you're not designing at all. You're stumbling in the dark. It's not an accident that every chapter in the Gang of Four's Design Patterns book includes a "Consequences" section that describes when and why using a pattern is inappropriate.