<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Bean of the Devil: Why Getters, Setters and Such are Evil</title>
	<atom:link href="http://pathfindersoftware.com/2009/02/bean-of-the-devil-why-getters-setters-and-such-are-evil/feed/" rel="self" type="application/rss+xml" />
	<link>http://pathfindersoftware.com/2009/02/bean-of-the-devil-why-getters-setters-and-such-are-evil/</link>
	<description>The Fastest Way to Launch Successful Software</description>
	<lastBuildDate>Thu, 19 Jan 2012 16:36:03 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Hao Wooi Lim</title>
		<link>http://pathfindersoftware.com/2009/02/bean-of-the-devil-why-getters-setters-and-such-are-evil/#comment-9311</link>
		<dc:creator>Hao Wooi Lim</dc:creator>
		<pubDate>Sat, 28 Feb 2009 09:08:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1408#comment-9311</guid>
		<description>I had to agree with you. Coming from a functional programming world, I kinda prefer the idea that states are nothing more than constructs for optimization and that if you must have states, then it can only be modifiable or readable through the class&#039;s methods. Allowing private member to be modifiable through public setter is just as evil as a public member, period.</description>
		<content:encoded><![CDATA[<p>I had to agree with you. Coming from a functional programming world, I kinda prefer the idea that states are nothing more than constructs for optimization and that if you must have states, then it can only be modifiable or readable through the class&#8217;s methods. Allowing private member to be modifiable through public setter is just as evil as a public member, period.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dietrich Kappe</title>
		<link>http://pathfindersoftware.com/2009/02/bean-of-the-devil-why-getters-setters-and-such-are-evil/#comment-9310</link>
		<dc:creator>Dietrich Kappe</dc:creator>
		<pubDate>Fri, 27 Feb 2009 21:32:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1408#comment-9310</guid>
		<description>@James

You&#039;re correct. I was thinking back to early versions of Hibernate and Spring where this was necessary. In point of fact, you can dispense with getters and setters for the most part, making their use even less forgivable. They are, as far as I&#039;m concerned, a code smell akin to stuffing everything into one main() method.</description>
		<content:encoded><![CDATA[<p>@James</p>
<p>You&#8217;re correct. I was thinking back to early versions of Hibernate and Spring where this was necessary. In point of fact, you can dispense with getters and setters for the most part, making their use even less forgivable. They are, as far as I&#8217;m concerned, a code smell akin to stuffing everything into one main() method.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Law</title>
		<link>http://pathfindersoftware.com/2009/02/bean-of-the-devil-why-getters-setters-and-such-are-evil/#comment-9309</link>
		<dc:creator>James Law</dc:creator>
		<pubDate>Fri, 27 Feb 2009 20:42:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1408#comment-9309</guid>
		<description>FYI, neither hibernate nor spring require get/set pairs. Not sure if you&#039;re suggesting that, but I&#039;m amazed at the # of people who believe this is the case. Check out fowlers post on getter/setter eradicator.
 http://martinfowler.com/bliki/GetterEradicator.html</description>
		<content:encoded><![CDATA[<p>FYI, neither hibernate nor spring require get/set pairs. Not sure if you&#8217;re suggesting that, but I&#8217;m amazed at the # of people who believe this is the case. Check out fowlers post on getter/setter eradicator.<br />
 <a href="http://martinfowler.com/bliki/GetterEradicator.html" rel="nofollow">http://martinfowler.com/bliki/GetterEradicator.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dietrich Kappe</title>
		<link>http://pathfindersoftware.com/2009/02/bean-of-the-devil-why-getters-setters-and-such-are-evil/#comment-9308</link>
		<dc:creator>Dietrich Kappe</dc:creator>
		<pubDate>Fri, 27 Feb 2009 18:45:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1408#comment-9308</guid>
		<description>@Getter.getAlternatives()

First, in languages that support interfaces, put all of the getter/setter methods in an interface, then only use that interface in system boundary contexts.

Second, practice good OO. Don&#039;t pass primitive types (other than booleans) around as parameters and return values.

Third, for those cases where you do need implementation details, such as computing aggregate values from a collection of objects, make sure the circle of collaborating objects that have this tight coupling is specific and small. The moment it gets larger, you have a refactor on your hands.</description>
		<content:encoded><![CDATA[<p>@Getter.getAlternatives()</p>
<p>First, in languages that support interfaces, put all of the getter/setter methods in an interface, then only use that interface in system boundary contexts.</p>
<p>Second, practice good OO. Don&#8217;t pass primitive types (other than booleans) around as parameters and return values.</p>
<p>Third, for those cases where you do need implementation details, such as computing aggregate values from a collection of objects, make sure the circle of collaborating objects that have this tight coupling is specific and small. The moment it gets larger, you have a refactor on your hands.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Getter.getAlternatives()</title>
		<link>http://pathfindersoftware.com/2009/02/bean-of-the-devil-why-getters-setters-and-such-are-evil/#comment-9307</link>
		<dc:creator>Getter.getAlternatives()</dc:creator>
		<pubDate>Fri, 27 Feb 2009 17:44:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1408#comment-9307</guid>
		<description>This is an interesting post.  I see 1-5 as reasons to use getters and setters.  Certainly, getters and setters should be only used when a design intends that the specific internal be viewed/replaced by users of the object.

What alternative to getters and setters do you recommend?  Non-private member variables (laughing)?

@MoffDub - very insightful post.  Too bad it&#039;s a lot of work to do this.  I would recommend only doing this for client/module/library APIs that will be called by an unknown set of users.</description>
		<content:encoded><![CDATA[<p>This is an interesting post.  I see 1-5 as reasons to use getters and setters.  Certainly, getters and setters should be only used when a design intends that the specific internal be viewed/replaced by users of the object.</p>
<p>What alternative to getters and setters do you recommend?  Non-private member variables (laughing)?</p>
<p>@MoffDub &#8211; very insightful post.  Too bad it&#8217;s a lot of work to do this.  I would recommend only doing this for client/module/library APIs that will be called by an unknown set of users.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dietrich Kappe</title>
		<link>http://pathfindersoftware.com/2009/02/bean-of-the-devil-why-getters-setters-and-such-are-evil/#comment-9306</link>
		<dc:creator>Dietrich Kappe</dc:creator>
		<pubDate>Fri, 27 Feb 2009 17:11:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1408#comment-9306</guid>
		<description>@chang

Can you be more specific? You love the getters and setters?</description>
		<content:encoded><![CDATA[<p>@chang</p>
<p>Can you be more specific? You love the getters and setters?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MoffDub</title>
		<link>http://pathfindersoftware.com/2009/02/bean-of-the-devil-why-getters-setters-and-such-are-evil/#comment-9305</link>
		<dc:creator>MoffDub</dc:creator>
		<pubDate>Fri, 27 Feb 2009 12:17:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1408#comment-9305</guid>
		<description>Ah, the timeless &quot;Getters and Setters Are Evil&quot; topic. I have devoted many a blog post to this: http://moffdub.wordpress.com/tag/getters-and-setters-are-evil/

Anyway, here&#039;s the conclusion I most recently came to on this. The catch phrase shouldn&#039;t be &quot;getters and setters are evil&quot;, but rather &quot;revealing internal implementation details and enabling procedural-style programming is evil.&quot;

If you are practicing something like domain-driven design, then I see nothing particularly evil about having getters for the fields of a domain object, as long as you encapsulate those values into an object. Also, these fields need to be domain-relevant fields, which they all should be if you are really keeping the domain model clean.

For instance, instead of having the Customer object&#039;s getID() return and int or a long or whatever it is, return a CustomerID object. Any logic you need to perform with it, like comparison, should be methods of CustomerID.

Similarly, when you need the actual value for the UI or persistence, say CustomerID.asString(). This way, if the internal implementation of CustomerID changes from int to long, no other class is affected.

Some other words on this: you should also probably return copies of such objects for these getters, unless you can absolutely guarantee that the objects returned are immutable. If not, then changing the returned object can muck with the containing object&#039;s implementation in a way inconsistent with its API.

Another thing is I think setters for every fields ARE in fact evil. If you have getters for every field, and setters for every field, you have devolved, as you pointed out, to procedural programming. Setters are fine if they make sense for the object (i.e. the requirement is that customers can move to a new address, so Customer.setAddress(&quot;123 Main Street&quot;) ). The setters for fields that are only set once need to be one-time only... in other words, use a constructor.</description>
		<content:encoded><![CDATA[<p>Ah, the timeless &#8220;Getters and Setters Are Evil&#8221; topic. I have devoted many a blog post to this: <a href="http://moffdub.wordpress.com/tag/getters-and-setters-are-evil/" rel="nofollow">http://moffdub.wordpress.com/tag/getters-and-setters-are-evil/</a></p>
<p>Anyway, here&#8217;s the conclusion I most recently came to on this. The catch phrase shouldn&#8217;t be &#8220;getters and setters are evil&#8221;, but rather &#8220;revealing internal implementation details and enabling procedural-style programming is evil.&#8221;</p>
<p>If you are practicing something like domain-driven design, then I see nothing particularly evil about having getters for the fields of a domain object, as long as you encapsulate those values into an object. Also, these fields need to be domain-relevant fields, which they all should be if you are really keeping the domain model clean.</p>
<p>For instance, instead of having the Customer object&#8217;s getID() return and int or a long or whatever it is, return a CustomerID object. Any logic you need to perform with it, like comparison, should be methods of CustomerID.</p>
<p>Similarly, when you need the actual value for the UI or persistence, say CustomerID.asString(). This way, if the internal implementation of CustomerID changes from int to long, no other class is affected.</p>
<p>Some other words on this: you should also probably return copies of such objects for these getters, unless you can absolutely guarantee that the objects returned are immutable. If not, then changing the returned object can muck with the containing object&#8217;s implementation in a way inconsistent with its API.</p>
<p>Another thing is I think setters for every fields ARE in fact evil. If you have getters for every field, and setters for every field, you have devolved, as you pointed out, to procedural programming. Setters are fine if they make sense for the object (i.e. the requirement is that customers can move to a new address, so Customer.setAddress(&#8220;123 Main Street&#8221;) ). The setters for fields that are only set once need to be one-time only&#8230; in other words, use a constructor.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: chang</title>
		<link>http://pathfindersoftware.com/2009/02/bean-of-the-devil-why-getters-setters-and-such-are-evil/#comment-9304</link>
		<dc:creator>chang</dc:creator>
		<pubDate>Fri, 27 Feb 2009 09:00:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1408#comment-9304</guid>
		<description>I agree with none of what you just said. I think you&#039;re completely wrong.</description>
		<content:encoded><![CDATA[<p>I agree with none of what you just said. I think you&#8217;re completely wrong.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dietrich Kappe</title>
		<link>http://pathfindersoftware.com/2009/02/bean-of-the-devil-why-getters-setters-and-such-are-evil/#comment-9303</link>
		<dc:creator>Dietrich Kappe</dc:creator>
		<pubDate>Fri, 27 Feb 2009 06:31:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1408#comment-9303</guid>
		<description>@Antoine

They can be used in certain contexts, but only as part of an interface whose use is restricted.</description>
		<content:encoded><![CDATA[<p>@Antoine</p>
<p>They can be used in certain contexts, but only as part of an interface whose use is restricted.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Antoine Leclair</title>
		<link>http://pathfindersoftware.com/2009/02/bean-of-the-devil-why-getters-setters-and-such-are-evil/#comment-9302</link>
		<dc:creator>Antoine Leclair</dc:creator>
		<pubDate>Fri, 27 Feb 2009 03:05:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=1408#comment-9302</guid>
		<description>I&#039;m not sure to get your point. You are saying getters/setters are bad in general?

Or are you saying they simply should not be used to expose all the internals of a class?</description>
		<content:encoded><![CDATA[<p>I&#8217;m not sure to get your point. You are saying getters/setters are bad in general?</p>
<p>Or are you saying they simply should not be used to expose all the internals of a class?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic (User agent is rejected)
Page Caching using memcached (User agent is rejected)

Served from: pathfindersoftware.com @ 2012-02-10 02:50:11 -->
