<?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: Properties &#8211; A False Sense of Encapsulation</title>
	<atom:link href="http://elegantcode.com/2008/09/26/properties-a-false-sense-of-encapsulation/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com/2008/09/26/properties-a-false-sense-of-encapsulation/</link>
	<description></description>
	<lastBuildDate>Sun, 14 Mar 2010 12:04:09 -0500</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Along Came Betty &#187; Porting Soar to Java or: How I Learned to Stop Worrying and Love Spaghetti (Part 2)</title>
		<link>http://elegantcode.com/2008/09/26/properties-a-false-sense-of-encapsulation/comment-page-2/#comment-41259</link>
		<dc:creator>Along Came Betty &#187; Porting Soar to Java or: How I Learned to Stop Worrying and Love Spaghetti (Part 2)</dc:creator>
		<pubDate>Sat, 27 Dec 2008 03:35:18 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2008/09/26/properties-a-false-sense-of-encapsulation/#comment-41259</guid>
		<description>[...] I want the Agent class to be straightforward without a bunch of yucky public members or just as yucky public accessors.  I also want an interface that will allow me to refactor all these modules slowly over time [...]</description>
		<content:encoded><![CDATA[<p>[...] I want the Agent class to be straightforward without a bunch of yucky public members or just as yucky public accessors.  I also want an interface that will allow me to refactor all these modules slowly over time [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Colin Jack</title>
		<link>http://elegantcode.com/2008/09/26/properties-a-false-sense-of-encapsulation/comment-page-2/#comment-34628</link>
		<dc:creator>Colin Jack</dc:creator>
		<pubDate>Sun, 05 Oct 2008 19:56:33 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2008/09/26/properties-a-false-sense-of-encapsulation/#comment-34628</guid>
		<description>Definitely going to give this a good read before responding but on the Time And Money example, I think this is a special case where you&#039;re breaking the encapsulation provided by a simple value object (Money) to provide access to the &quot;raw&quot; value. Design wise that&#039;s a very different world from using a property to allow you to set a Customers Address vs. using methods for get/set.</description>
		<content:encoded><![CDATA[<p>Definitely going to give this a good read before responding but on the Time And Money example, I think this is a special case where you&#8217;re breaking the encapsulation provided by a simple value object (Money) to provide access to the &#8220;raw&#8221; value. Design wise that&#8217;s a very different world from using a property to allow you to set a Customers Address vs. using methods for get/set.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jan Van Ryswyck</title>
		<link>http://elegantcode.com/2008/09/26/properties-a-false-sense-of-encapsulation/comment-page-2/#comment-34481</link>
		<dc:creator>Jan Van Ryswyck</dc:creator>
		<pubDate>Sat, 04 Oct 2008 18:11:28 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2008/09/26/properties-a-false-sense-of-encapsulation/#comment-34481</guid>
		<description>I have mixed feelings about automatic properties. To me, they like public member variables all over again. 

I try to only incorporate a property when I&#039;m with my back against the wall. If I can deliver cleaner code by incorporating a method, than I always choose for this option.</description>
		<content:encoded><![CDATA[<p>I have mixed feelings about automatic properties. To me, they like public member variables all over again. </p>
<p>I try to only incorporate a property when I&#8217;m with my back against the wall. If I can deliver cleaner code by incorporating a method, than I always choose for this option.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dcarver</title>
		<link>http://elegantcode.com/2008/09/26/properties-a-false-sense-of-encapsulation/comment-page-2/#comment-34317</link>
		<dc:creator>dcarver</dc:creator>
		<pubDate>Fri, 03 Oct 2008 19:36:29 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2008/09/26/properties-a-false-sense-of-encapsulation/#comment-34317</guid>
		<description>Maybe I am to old school on Object design.  I always thought of properties as fairly obvious.  For example location is a property.  It probably should be readonly but it is a property of a person no matter what.

Changing location is a behavior of a person.  So by allowing the user to change the location property without invoking a method (in this case) to re locate themselves seems wrong.

Color might be another good example.  I can not change my color with out invoking some behavior (golaybythepool(...)  - which right now sounds like a good idea).

So I guess I would say that you should expose the properties as read only, since they are properties of the object.  Then provide methods to change readonly properties acording to the buisness rules.  

Either way properties can include buisness rules as needed.  I you want simple poperties you should use the new automatic properties in C# 3.0 and then they are truly simple properties with no buisness rules asssociated with them. By using automatic properties you enforce that restriction.  That way if you write the code for a property get/set as above it would imply you have additional logic to enforce beyond setting the local variable..</description>
		<content:encoded><![CDATA[<p>Maybe I am to old school on Object design.  I always thought of properties as fairly obvious.  For example location is a property.  It probably should be readonly but it is a property of a person no matter what.</p>
<p>Changing location is a behavior of a person.  So by allowing the user to change the location property without invoking a method (in this case) to re locate themselves seems wrong.</p>
<p>Color might be another good example.  I can not change my color with out invoking some behavior (golaybythepool(&#8230;)  &#8211; which right now sounds like a good idea).</p>
<p>So I guess I would say that you should expose the properties as read only, since they are properties of the object.  Then provide methods to change readonly properties acording to the buisness rules.  </p>
<p>Either way properties can include buisness rules as needed.  I you want simple poperties you should use the new automatic properties in C# 3.0 and then they are truly simple properties with no buisness rules asssociated with them. By using automatic properties you enforce that restriction.  That way if you write the code for a property get/set as above it would imply you have additional logic to enforce beyond setting the local variable..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Morten Lyhr</title>
		<link>http://elegantcode.com/2008/09/26/properties-a-false-sense-of-encapsulation/comment-page-1/#comment-34032</link>
		<dc:creator>Morten Lyhr</dc:creator>
		<pubDate>Wed, 01 Oct 2008 20:02:44 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2008/09/26/properties-a-false-sense-of-encapsulation/#comment-34032</guid>
		<description>You can read my view on Data Structures and Encapsulaed Objects here: http://morten.lyhr.dk/2008/10/data-structures-vs-encapsulation.html</description>
		<content:encoded><![CDATA[<p>You can read my view on Data Structures and Encapsulaed Objects here: <a href="http://morten.lyhr.dk/2008/10/data-structures-vs-encapsulation.html" rel="nofollow">http://morten.lyhr.dk/2008/10/data-structures-vs-encapsulation.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jan Van Ryswyck</title>
		<link>http://elegantcode.com/2008/09/26/properties-a-false-sense-of-encapsulation/comment-page-1/#comment-33947</link>
		<dc:creator>Jan Van Ryswyck</dc:creator>
		<pubDate>Tue, 30 Sep 2008 17:46:24 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2008/09/26/properties-a-false-sense-of-encapsulation/#comment-33947</guid>
		<description>@OAB: There are a lot of scenarios where Domain services are the right thing to do. As you know, they are part of the domain as well. The gist of this post is to avoid getters/setters until you have a valid case for them. 

Building an anemic domain model for a complex system is an anti-pattern I&#039;ve seen too much the last couple of years. Such a code base typically has a lot of duplicate code an is very hard to maintain.

An anemic domain is perfectly valid in simple, data viewing applications. This is the active-record scenario where the objects are DTO&#039;s.

All I&#039;m saying is that by putting the behavior where the data is, I&#039;m achieving more orthogonality. This is what OOP is all about.</description>
		<content:encoded><![CDATA[<p>@OAB: There are a lot of scenarios where Domain services are the right thing to do. As you know, they are part of the domain as well. The gist of this post is to avoid getters/setters until you have a valid case for them. </p>
<p>Building an anemic domain model for a complex system is an anti-pattern I&#8217;ve seen too much the last couple of years. Such a code base typically has a lot of duplicate code an is very hard to maintain.</p>
<p>An anemic domain is perfectly valid in simple, data viewing applications. This is the active-record scenario where the objects are DTO&#8217;s.</p>
<p>All I&#8217;m saying is that by putting the behavior where the data is, I&#8217;m achieving more orthogonality. This is what OOP is all about.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: trasa</title>
		<link>http://elegantcode.com/2008/09/26/properties-a-false-sense-of-encapsulation/comment-page-1/#comment-33937</link>
		<dc:creator>trasa</dc:creator>
		<pubDate>Tue, 30 Sep 2008 15:32:59 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2008/09/26/properties-a-false-sense-of-encapsulation/#comment-33937</guid>
		<description>He&#039;s not saying &#039;never use services,&#039; and neither am I.  So what does that have to do with the premise (that reliance on properties are a warning of bad design&#039;)?</description>
		<content:encoded><![CDATA[<p>He&#8217;s not saying &#8216;never use services,&#8217; and neither am I.  So what does that have to do with the premise (that reliance on properties are a warning of bad design&#8217;)?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: OAB</title>
		<link>http://elegantcode.com/2008/09/26/properties-a-false-sense-of-encapsulation/comment-page-1/#comment-33933</link>
		<dc:creator>OAB</dc:creator>
		<pubDate>Tue, 30 Sep 2008 14:51:22 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2008/09/26/properties-a-false-sense-of-encapsulation/#comment-33933</guid>
		<description>I think those yelling YAGNI are missing the point -- once you *do* need it, one of the premises of this blog post falls down -- i.e. that business rules belong inside of domain objects.</description>
		<content:encoded><![CDATA[<p>I think those yelling YAGNI are missing the point &#8212; once you *do* need it, one of the premises of this blog post falls down &#8212; i.e. that business rules belong inside of domain objects.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: trasa</title>
		<link>http://elegantcode.com/2008/09/26/properties-a-false-sense-of-encapsulation/comment-page-1/#comment-33862</link>
		<dc:creator>trasa</dc:creator>
		<pubDate>Mon, 29 Sep 2008 16:44:30 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2008/09/26/properties-a-false-sense-of-encapsulation/#comment-33862</guid>
		<description>@Bill: if making Customer culture-aware is not a requirement, leaving the code in Customer makes sense because everything is self-contained.  

This isn&#039;t comparable with Free Shipping as that code requires interaction from all sorts of entities, it makes sense to have a Service orchestrate that.

If, through agile design, we&#039;ve uncovered a new requirement [that we&#039;re going to be operating bars all over the world] then we just change the design and promote the age code to a culture-aware service; otherwise, YAGNI.</description>
		<content:encoded><![CDATA[<p>@Bill: if making Customer culture-aware is not a requirement, leaving the code in Customer makes sense because everything is self-contained.  </p>
<p>This isn&#8217;t comparable with Free Shipping as that code requires interaction from all sorts of entities, it makes sense to have a Service orchestrate that.</p>
<p>If, through agile design, we&#8217;ve uncovered a new requirement [that we're going to be operating bars all over the world] then we just change the design and promote the age code to a culture-aware service; otherwise, YAGNI.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bill Pierce</title>
		<link>http://elegantcode.com/2008/09/26/properties-a-false-sense-of-encapsulation/comment-page-1/#comment-33856</link>
		<dc:creator>Bill Pierce</dc:creator>
		<pubDate>Mon, 29 Sep 2008 15:38:29 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2008/09/26/properties-a-false-sense-of-encapsulation/#comment-33856</guid>
		<description>Anemic or not, I have to agree with David.  You will already have to modify CanHaveBeer() to accept some sort of CurrentLocation, because your Customer wouldn&#039;t be old enough to drink when visiting my country :)

Consider the more plausible example of determining if an order qualifies for free shipping.  Are you telling me you would hang that behavior on your Order domain object?  Me thinks not.</description>
		<content:encoded><![CDATA[<p>Anemic or not, I have to agree with David.  You will already have to modify CanHaveBeer() to accept some sort of CurrentLocation, because your Customer wouldn&#8217;t be old enough to drink when visiting my country <img src='http://elegantcode.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Consider the more plausible example of determining if an order qualifies for free shipping.  Are you telling me you would hang that behavior on your Order domain object?  Me thinks not.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
