<?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"
	>
<channel>
	<title>Comments on: The getter, the setter, the thinking and the box</title>
	<atom:link href="http://nutrun.com/weblog/the-getter-the-setter-the-thinking-and-the-box/feed/" rel="self" type="application/rss+xml" />
	<link>http://nutrun.com/weblog/the-getter-the-setter-the-thinking-and-the-box/</link>
	<description>nutrun</description>
	<pubDate>Thu, 20 Nov 2008 12:35:28 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
		<item>
		<title>By: keith ray</title>
		<link>http://nutrun.com/weblog/the-getter-the-setter-the-thinking-and-the-box/#comment-117</link>
		<dc:creator>keith ray</dc:creator>
		<pubDate>Fri, 14 Jul 2006 14:09:04 +0000</pubDate>
		<guid isPermaLink="false">http://new-site.nutrun.com/?p=30#comment-117</guid>
		<description>http://c2.com/cgi/wiki?TellDontAsk

Tell, don't ask. Single-responsibility methods do things, and maybe take parameters to help them do them. (Don't combine setters and doers, though.)</description>
		<content:encoded><![CDATA[<p><a href="http://c2.com/cgi/wiki?TellDontAsk" rel="nofollow">http://c2.com/cgi/wiki?TellDontAsk</a></p>
<p>Tell, don&#8217;t ask. Single-responsibility methods do things, and maybe take parameters to help them do them. (Don&#8217;t combine setters and doers, though.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Reedo</title>
		<link>http://nutrun.com/weblog/the-getter-the-setter-the-thinking-and-the-box/#comment-116</link>
		<dc:creator>Reedo</dc:creator>
		<pubDate>Fri, 30 Jun 2006 17:48:50 +0000</pubDate>
		<guid isPermaLink="false">http://new-site.nutrun.com/?p=30#comment-116</guid>
		<description>It isn't wrong to use more complex logic in getters and setters, because the very purpose of using a getter or setter rather than a public property is encapsulation: to allow the object implementation with its private data to change without breaking code that relies on it! Even if a getter or setter starts out as braindead, in the future the object can put any code there that should be executed when the property value changes or gets accessed. If it was just a public property and not a getter/setter pair, that code would have to be duplicated everywhere that the object's property is manipulated--outside the object--and that would be awful to maintain.</description>
		<content:encoded><![CDATA[<p>It isn&#8217;t wrong to use more complex logic in getters and setters, because the very purpose of using a getter or setter rather than a public property is encapsulation: to allow the object implementation with its private data to change without breaking code that relies on it! Even if a getter or setter starts out as braindead, in the future the object can put any code there that should be executed when the property value changes or gets accessed. If it was just a public property and not a getter/setter pair, that code would have to be duplicated everywhere that the object&#8217;s property is manipulated&#8211;outside the object&#8211;and that would be awful to maintain.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Ingles</title>
		<link>http://nutrun.com/weblog/the-getter-the-setter-the-thinking-and-the-box/#comment-115</link>
		<dc:creator>Paul Ingles</dc:creator>
		<pubDate>Fri, 30 Jun 2006 17:22:46 +0000</pubDate>
		<guid isPermaLink="false">http://new-site.nutrun.com/?p=30#comment-115</guid>
		<description>Eddy,

Possibly, and as my Economics master used to suggest I answer every question with: It depends.

In this instance, all we're talking about is the loading of data. There's no funky monkey-business with "if this child object doesn't exist yet, create it, and then return it".

It's a slightly different use of the Lazy Initialisation pattern - where we're not really attempting to delay database access, rather instead to improve our test code. The benefit was a JUnit TestCase that we didn't need to edit every other testXxxx every time we changed our action.

However, I have seen strange behaviour through too much logic in getters (primarily from my years of .NET work). In this instance though, I don't think it's doing too much more than what a standard getter would be doing.</description>
		<content:encoded><![CDATA[<p>Eddy,</p>
<p>Possibly, and as my Economics master used to suggest I answer every question with: It depends.</p>
<p>In this instance, all we&#8217;re talking about is the loading of data. There&#8217;s no funky monkey-business with &#8220;if this child object doesn&#8217;t exist yet, create it, and then return it&#8221;.</p>
<p>It&#8217;s a slightly different use of the Lazy Initialisation pattern - where we&#8217;re not really attempting to delay database access, rather instead to improve our test code. The benefit was a JUnit TestCase that we didn&#8217;t need to edit every other testXxxx every time we changed our action.</p>
<p>However, I have seen strange behaviour through too much logic in getters (primarily from my years of .NET work). In this instance though, I don&#8217;t think it&#8217;s doing too much more than what a standard getter would be doing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jaka Jaksic</title>
		<link>http://nutrun.com/weblog/the-getter-the-setter-the-thinking-and-the-box/#comment-114</link>
		<dc:creator>Jaka Jaksic</dc:creator>
		<pubDate>Fri, 30 Jun 2006 14:12:05 +0000</pubDate>
		<guid isPermaLink="false">http://new-site.nutrun.com/?p=30#comment-114</guid>
		<description>It is not "wrong", but it may have unexpected side-effects if you use such classes with tools, such as Hibernate, which expect getters and setters (and constructors) to be plain and simple. I often put some extra code in those methods, because I find it convenient, but quite often funny stuff started happening afterwards, e.g. wrong values being read/saved to the database or getters/setters being executed at inappropriate times, like before the aplication was fully initialized.

If you only use those classes yourself, in a controled way, then it's ok to have more complex getters/setters/constructors. If they are used by 3rd party bean handling tools, then you can still make them complex, but you have to be careful with what you do. You have to be aware that those tools expect these methods to be simple and that they can call them anyhow, at any time.</description>
		<content:encoded><![CDATA[<p>It is not &#8220;wrong&#8221;, but it may have unexpected side-effects if you use such classes with tools, such as Hibernate, which expect getters and setters (and constructors) to be plain and simple. I often put some extra code in those methods, because I find it convenient, but quite often funny stuff started happening afterwards, e.g. wrong values being read/saved to the database or getters/setters being executed at inappropriate times, like before the aplication was fully initialized.</p>
<p>If you only use those classes yourself, in a controled way, then it&#8217;s ok to have more complex getters/setters/constructors. If they are used by 3rd party bean handling tools, then you can still make them complex, but you have to be careful with what you do. You have to be aware that those tools expect these methods to be simple and that they can call them anyhow, at any time.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tony Marston</title>
		<link>http://nutrun.com/weblog/the-getter-the-setter-the-thinking-and-the-box/#comment-113</link>
		<dc:creator>Tony Marston</dc:creator>
		<pubDate>Fri, 30 Jun 2006 13:20:26 +0000</pubDate>
		<guid isPermaLink="false">http://new-site.nutrun.com/?p=30#comment-113</guid>
		<description>Although I do not use Java (I use PHP or all my web work) I decided not t use getters and setters from day 1. Rather than inserting or etracting values one field at a time I do it en mass via an associative array. This means I have have generic methods such as:

$array = $object-&#38;gt;getData($where);

$array = $object-&#38;gt;insertRecord($array);

$array = $object-&#38;gt;updateRecord($array);

$array = $object-&#38;gt;deleteRecord($where);

All these calls are inside page controllers, and as no object names or field names are hard-coded I do not need a separate customised controller for each model. This means I can make use of a standard set of reusable controllers where the class name(s) from which the objects are instantiated are passed in as parameters.

I would not e able to achieve the same level of code resuse with getters and setters, therefore getters and setters are evil.</description>
		<content:encoded><![CDATA[<p>Although I do not use Java (I use PHP or all my web work) I decided not t use getters and setters from day 1. Rather than inserting or etracting values one field at a time I do it en mass via an associative array. This means I have have generic methods such as:</p>
<p>$array = $object-&#38;gt;getData($where);</p>
<p>$array = $object-&#38;gt;insertRecord($array);</p>
<p>$array = $object-&#38;gt;updateRecord($array);</p>
<p>$array = $object-&#38;gt;deleteRecord($where);</p>
<p>All these calls are inside page controllers, and as no object names or field names are hard-coded I do not need a separate customised controller for each model. This means I can make use of a standard set of reusable controllers where the class name(s) from which the objects are instantiated are passed in as parameters.</p>
<p>I would not e able to achieve the same level of code resuse with getters and setters, therefore getters and setters are evil.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eddy Young</title>
		<link>http://nutrun.com/weblog/the-getter-the-setter-the-thinking-and-the-box/#comment-112</link>
		<dc:creator>Eddy Young</dc:creator>
		<pubDate>Fri, 30 Jun 2006 12:49:09 +0000</pubDate>
		<guid isPermaLink="false">http://new-site.nutrun.com/?p=30#comment-112</guid>
		<description>Isn't it "wrong" to use a getter to execute logic code more complex than a simple fetching of a property value?</description>
		<content:encoded><![CDATA[<p>Isn&#8217;t it &#8220;wrong&#8221; to use a getter to execute logic code more complex than a simple fetching of a property value?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Law</title>
		<link>http://nutrun.com/weblog/the-getter-the-setter-the-thinking-and-the-box/#comment-109</link>
		<dc:creator>James Law</dc:creator>
		<pubDate>Thu, 29 Jun 2006 23:15:01 +0000</pubDate>
		<guid isPermaLink="false">http://new-site.nutrun.com/?p=30#comment-109</guid>
		<description>Hey, I agree the whole requirment of get/set stinks. FYI, in hibernate, you do not actually need them. Just use access="field" instead of property.

One down, 3 frameworks to go though.

One thing my teams do since we hate struts actions, is
1. use dispatch action
2. move almost all logic into the form- typical actions can then be about 3-4 lines:
1. cast form
2. have form do something
3. choose view

Cheers
James</description>
		<content:encoded><![CDATA[<p>Hey, I agree the whole requirment of get/set stinks. FYI, in hibernate, you do not actually need them. Just use access=&#8221;field&#8221; instead of property.</p>
<p>One down, 3 frameworks to go though.</p>
<p>One thing my teams do since we hate struts actions, is<br />
1. use dispatch action<br />
2. move almost all logic into the form- typical actions can then be about 3-4 lines:<br />
1. cast form<br />
2. have form do something<br />
3. choose view</p>
<p>Cheers<br />
James</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom</title>
		<link>http://nutrun.com/weblog/the-getter-the-setter-the-thinking-and-the-box/#comment-111</link>
		<dc:creator>Tom</dc:creator>
		<pubDate>Thu, 29 Jun 2006 15:26:45 +0000</pubDate>
		<guid isPermaLink="false">http://new-site.nutrun.com/?p=30#comment-111</guid>
		<description>I've almost always felt pain when doing fancy stuff in getters and setters. (And that's actually a reason that I'm not too opposed to public fields, especially for non-exported code which you can auto-refactor into getters and setters if needed.) No examples off the top of my head. If I needed to decompose an execute() method, I'd probably prefer to do just that. Make helper methods or classes that do subtasks.

I prefer to have all the data ready and then start working with it rather than try to get too fancy with half-finished data or whatever. But I guess, as you said, the post isn't about actions.

I just prefer anemic domain models most of the time.</description>
		<content:encoded><![CDATA[<p>I&#8217;ve almost always felt pain when doing fancy stuff in getters and setters. (And that&#8217;s actually a reason that I&#8217;m not too opposed to public fields, especially for non-exported code which you can auto-refactor into getters and setters if needed.) No examples off the top of my head. If I needed to decompose an execute() method, I&#8217;d probably prefer to do just that. Make helper methods or classes that do subtasks.</p>
<p>I prefer to have all the data ready and then start working with it rather than try to get too fancy with half-finished data or whatever. But I guess, as you said, the post isn&#8217;t about actions.</p>
<p>I just prefer anemic domain models most of the time.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul (the dude)</title>
		<link>http://nutrun.com/weblog/the-getter-the-setter-the-thinking-and-the-box/#comment-110</link>
		<dc:creator>Paul (the dude)</dc:creator>
		<pubDate>Thu, 29 Jun 2006 07:27:25 +0000</pubDate>
		<guid isPermaLink="false">http://new-site.nutrun.com/?p=30#comment-110</guid>
		<description>Sometimes yes, myself in general, no :)</description>
		<content:encoded><![CDATA[<p>Sometimes yes, myself in general, no <img src='http://nutrun.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
</channel>
</rss>
