Note that there are some explanatory texts on larger screens.

plurals
  1. POAllen Holub wrote "You should never use get/set functions", is he correct?
    text
    copied!<p>Allen Holub wrote the following,</p> <blockquote> <p>You can't have a program without some coupling. Nonetheless, you can minimize coupling considerably by slavishly following OO (object-oriented) precepts (the most important is that the implementation of an object should be completely hidden from the objects that use it). For example, an object's instance variables (member fields that aren't constants), should always be private. Period. No exceptions. Ever. I mean it. (You can occasionally use protected methods effectively, but protected instance variables are an abomination.)</p> </blockquote> <p>Which sounds reasonable, but he then goes on to say,</p> <blockquote> <p>You should <b>never use get/set functions</b> for the same reason—they're just overly complicated ways to make a field public (though access functions that return full-blown objects rather than a basic-type value are reasonable in situations where the returned object's class is a key abstraction in the design).</p> </blockquote> <p>Which, frankly, just sounds insane to me.</p> <p>I understand the principle of information hiding, but without accessors and mutators you couldn't use Java beans at all. I don't know how you would follow a MVC design without accessors in the model, since the model <em>can not</em> be responsible for rendering the view.</p> <p>However, I am a younger programmer and I learn more about Object Oriented Design everyday. Perhaps someone with more experience can weigh in on this issue.</p> <h2>Allen Holub's articles for reference</h2> <ul> <li><a href="http://www.javaworld.com/javaworld/jw-08-2003/jw-0801-toolbox.html?page=1" rel="nofollow noreferrer">Why Extends Is Evil</a></li> <li><a href="http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html" rel="nofollow noreferrer">Why Getter And Setter Methods Are Evil</a></li> </ul> <hr> <h1>Related Questions:</h1> <blockquote> <ul> <li><a href="https://stackoverflow.com/questions/565095/java-are-getters-and-setters-evil">Java: Are Getters and Setters evil?</a></li> <li><a href="https://stackoverflow.com/questions/808348/is-it-really-that-wrong-not-using-setters-and-getters">Is it really that wrong not using setters and getters?</a></li> <li><a href="https://stackoverflow.com/questions/737409/are-get-and-set-functions-popular-with-c-programmers">Are get and set functions popular with C++ programmers?</a></li> <li><a href="https://stackoverflow.com/questions/476021/should-you-use-accessor-properties-from-within-the-class-or-just-from-outside-of">Should you use accessor properties from within the class, or just from outside of the class?</a></li> </ul> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload