<?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: The power of immutability in a Rich Domain Model</title>
	<atom:link href="http://www.gridshore.nl/2009/04/06/the-power-of-immutability-in-a-rich-domain-model/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gridshore.nl/2009/04/06/the-power-of-immutability-in-a-rich-domain-model/</link>
	<description>A weblog about software engineering, Architecture, Technology an other things we like.</description>
	<lastBuildDate>Sat, 28 Jan 2012 20:11:11 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Jalal</title>
		<link>http://www.gridshore.nl/2009/04/06/the-power-of-immutability-in-a-rich-domain-model/comment-page-1/#comment-30549</link>
		<dc:creator>Jalal</dc:creator>
		<pubDate>Tue, 09 Nov 2010 12:22:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.gridshore.nl/?p=696#comment-30549</guid>
		<description>Now, with new versions of hibernate you can use final fields and private default constructors, consequently,  in private default constructor final fields can be set to null or any arbitrary default. because constructor is private, no ordinary code can call it, just hibernate.
After calling private default constructor by hibernate , hibernate will directly set final fields from Data source. data source already contains valid data and thus entity created by hibernate is already valid.
hibernate ability to set final variables, calling private constructors, and directly accessing field. are good features which enables rich domain model.</description>
		<content:encoded><![CDATA[<p>Now, with new versions of hibernate you can use final fields and private default constructors, consequently,  in private default constructor final fields can be set to null or any arbitrary default. because constructor is private, no ordinary code can call it, just hibernate.<br />
After calling private default constructor by hibernate , hibernate will directly set final fields from Data source. data source already contains valid data and thus entity created by hibernate is already valid.<br />
hibernate ability to set final variables, calling private constructors, and directly accessing field. are good features which enables rich domain model.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rikard</title>
		<link>http://www.gridshore.nl/2009/04/06/the-power-of-immutability-in-a-rich-domain-model/comment-page-1/#comment-30222</link>
		<dc:creator>Rikard</dc:creator>
		<pubDate>Sat, 27 Mar 2010 21:46:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.gridshore.nl/?p=696#comment-30222</guid>
		<description>Well i have hibernate in my domain model. But im shifting to remove hibernate in the future. It breaks the domain model, even if i have the annotations on the field level. Besides letting hibernate inject and clutter the entities with freamwork specific annotations well annotations is a dependency in disguise! I can rabble on why not to use Hibernate (and annotations)in a big size application but that is another post ;)

But this post gives a very good understanding about the power of domain models and aggregates and hey immutibility is the way to go for in all code :)</description>
		<content:encoded><![CDATA[<p>Well i have hibernate in my domain model. But im shifting to remove hibernate in the future. It breaks the domain model, even if i have the annotations on the field level. Besides letting hibernate inject and clutter the entities with freamwork specific annotations well annotations is a dependency in disguise! I can rabble on why not to use Hibernate (and annotations)in a big size application but that is another post <img src='http://www.gridshore.nl/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>But this post gives a very good understanding about the power of domain models and aggregates and hey immutibility is the way to go for in all code <img src='http://www.gridshore.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Allard</title>
		<link>http://www.gridshore.nl/2009/04/06/the-power-of-immutability-in-a-rich-domain-model/comment-page-1/#comment-23822</link>
		<dc:creator>Allard</dc:creator>
		<pubDate>Tue, 02 Jun 2009 19:41:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.gridshore.nl/?p=696#comment-23822</guid>
		<description>I just did a little quick research. Hibernate doesn&#039;t have any trouble changing the value of a final field. In fact, you can just make persisted fields final and set them to null or 0 in the default constructor.
However, I have no idea what this does to the multi-threading guarantees that final field provide. Typically, these objects are only &quot;shared&quot; among thread after they have been fully constructed and initialized by Hibernate.</description>
		<content:encoded><![CDATA[<p>I just did a little quick research. Hibernate doesn&#8217;t have any trouble changing the value of a final field. In fact, you can just make persisted fields final and set them to null or 0 in the default constructor.<br />
However, I have no idea what this does to the multi-threading guarantees that final field provide. Typically, these objects are only &#8220;shared&#8221; among thread after they have been fully constructed and initialized by Hibernate.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: RichB</title>
		<link>http://www.gridshore.nl/2009/04/06/the-power-of-immutability-in-a-rich-domain-model/comment-page-1/#comment-22919</link>
		<dc:creator>RichB</dc:creator>
		<pubDate>Tue, 19 May 2009 16:23:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.gridshore.nl/?p=696#comment-22919</guid>
		<description>I have an existing immutable domain model (immutable for a highly concurrent problem). I&#039;m replacing the data layer with Hibernate (NHibernate) actually and have the same problem as you. As far as I can see my options, they are: treat Hibernate as the Data Access layer and load my existing immutable domain model from the Hibernate entities (treating Hibernate as the Data Access layer). Alternatively (and related), make my immutable domain model &quot;wrap&quot; the Hibernate entities, making them immutable.</description>
		<content:encoded><![CDATA[<p>I have an existing immutable domain model (immutable for a highly concurrent problem). I&#8217;m replacing the data layer with Hibernate (NHibernate) actually and have the same problem as you. As far as I can see my options, they are: treat Hibernate as the Data Access layer and load my existing immutable domain model from the Hibernate entities (treating Hibernate as the Data Access layer). Alternatively (and related), make my immutable domain model &#8220;wrap&#8221; the Hibernate entities, making them immutable.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Allard</title>
		<link>http://www.gridshore.nl/2009/04/06/the-power-of-immutability-in-a-rich-domain-model/comment-page-1/#comment-22782</link>
		<dc:creator>Allard</dc:creator>
		<pubDate>Sun, 17 May 2009 08:35:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.gridshore.nl/?p=696#comment-22782</guid>
		<description>Zoran,

thanks for your pointers. The problem I encountered (and I always use the field access method) is that Hibernate needs a no-argument constructor. I&#039;ll try to see if I can initialize the final fields to some default values (0 or null) and see if hibernate can change the values even though the fields are final.</description>
		<content:encoded><![CDATA[<p>Zoran,</p>
<p>thanks for your pointers. The problem I encountered (and I always use the field access method) is that Hibernate needs a no-argument constructor. I&#8217;ll try to see if I can initialize the final fields to some default values (0 or null) and see if hibernate can change the values even though the fields are final.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zoran</title>
		<link>http://www.gridshore.nl/2009/04/06/the-power-of-immutability-in-a-rich-domain-model/comment-page-1/#comment-22750</link>
		<dc:creator>Zoran</dc:creator>
		<pubDate>Sat, 16 May 2009 22:18:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.gridshore.nl/?p=696#comment-22750</guid>
		<description>It is well worth to note that Hibernate (and possibly other ORM frameworks) do in fact work with immutable objects, but you have to set the access method to &#039;field&#039;. You may be wondering how can this help if your fields are final, well, since Java 1.5 they are not really final, checkout http://www.javaspecialists.eu/archive/Issue096.html .</description>
		<content:encoded><![CDATA[<p>It is well worth to note that Hibernate (and possibly other ORM frameworks) do in fact work with immutable objects, but you have to set the access method to &#8216;field&#8217;. You may be wondering how can this help if your fields are final, well, since Java 1.5 they are not really final, checkout <a href="http://www.javaspecialists.eu/archive/Issue096.html" rel="nofollow">http://www.javaspecialists.eu/archive/Issue096.html</a> .</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben</title>
		<link>http://www.gridshore.nl/2009/04/06/the-power-of-immutability-in-a-rich-domain-model/comment-page-1/#comment-21192</link>
		<dc:creator>Ben</dc:creator>
		<pubDate>Sun, 12 Apr 2009 22:00:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.gridshore.nl/?p=696#comment-21192</guid>
		<description>Allard,

Excellent post (as usual). It&#039;s good to see good people paying attention to proper domain modeling again -- perhaps we can start to get away from people being &quot;Java&quot; developers or &quot;Ruby&quot; developers or &quot;Popular flavor of the day&quot; developers and back to being software engineers for whom the exact implementation platform is a secondary concern.

You are correct as well about the important role immutability can and should play in design. Not because immutability is a &quot;cool&quot; idea or a &quot;best practice&quot; (i.e. the consulting reason for doing things). But because, as your example shows, sometimes things simply shouldn&#039;t change anymore. It is sometimes possible for an object to reach a terminal state after some time and in that case developers shouldn&#039;t be so afraid to incorporate that fact into their software design.

It is indeed a pity that frameworks like Hibernate and JPA don&#039;t offer direct support for value objects or (semi-)immutable objects. This is, of course, the drawback of the fundamental choice such frameworks make to base themselves on JavaBeans (even if they call themselves POJO frameworks). As dlemoing points out, you can get part of the way in Hibernate (use a CompositeUserType implementation to persist or recreate your immutable object). Unfortunately that means having to embed the immutable object in a dedicated container object that is then itself a JavaBean. You can hide that detail within your repository implementation (to use Evans&#039; terminology), but it&#039;s an awful lot of work.

In any case, good stuff once again. Keep it coming!</description>
		<content:encoded><![CDATA[<p>Allard,</p>
<p>Excellent post (as usual). It&#8217;s good to see good people paying attention to proper domain modeling again &#8212; perhaps we can start to get away from people being &#8220;Java&#8221; developers or &#8220;Ruby&#8221; developers or &#8220;Popular flavor of the day&#8221; developers and back to being software engineers for whom the exact implementation platform is a secondary concern.</p>
<p>You are correct as well about the important role immutability can and should play in design. Not because immutability is a &#8220;cool&#8221; idea or a &#8220;best practice&#8221; (i.e. the consulting reason for doing things). But because, as your example shows, sometimes things simply shouldn&#8217;t change anymore. It is sometimes possible for an object to reach a terminal state after some time and in that case developers shouldn&#8217;t be so afraid to incorporate that fact into their software design.</p>
<p>It is indeed a pity that frameworks like Hibernate and JPA don&#8217;t offer direct support for value objects or (semi-)immutable objects. This is, of course, the drawback of the fundamental choice such frameworks make to base themselves on JavaBeans (even if they call themselves POJO frameworks). As dlemoing points out, you can get part of the way in Hibernate (use a CompositeUserType implementation to persist or recreate your immutable object). Unfortunately that means having to embed the immutable object in a dedicated container object that is then itself a JavaBean. You can hide that detail within your repository implementation (to use Evans&#8217; terminology), but it&#8217;s an awful lot of work.</p>
<p>In any case, good stuff once again. Keep it coming!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Allard</title>
		<link>http://www.gridshore.nl/2009/04/06/the-power-of-immutability-in-a-rich-domain-model/comment-page-1/#comment-20765</link>
		<dc:creator>Allard</dc:creator>
		<pubDate>Tue, 07 Apr 2009 15:03:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.gridshore.nl/?p=696#comment-20765</guid>
		<description>Hi dlemoing,

Thanks for you remark and links to Evans&#039; pages. Perhaps in Evan&#039;s terms the OrderLine would be called a ValueObject, since it is fully immutable.

However, you can imagine a state field on a line item to indicate the processing state of that item. In that case, part of the entity is immutable, the other part isn&#039;t.

My key point is that immutability is, in my opinion, often overlooked as an option to reach certain goals.</description>
		<content:encoded><![CDATA[<p>Hi dlemoing,</p>
<p>Thanks for you remark and links to Evans&#8217; pages. Perhaps in Evan&#8217;s terms the OrderLine would be called a ValueObject, since it is fully immutable.</p>
<p>However, you can imagine a state field on a line item to indicate the processing state of that item. In that case, part of the entity is immutable, the other part isn&#8217;t.</p>
<p>My key point is that immutability is, in my opinion, often overlooked as an option to reach certain goals.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ravi</title>
		<link>http://www.gridshore.nl/2009/04/06/the-power-of-immutability-in-a-rich-domain-model/comment-page-1/#comment-20758</link>
		<dc:creator>Ravi</dc:creator>
		<pubDate>Tue, 07 Apr 2009 12:58:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.gridshore.nl/?p=696#comment-20758</guid>
		<description>Sorry did not read the conclusion</description>
		<content:encoded><![CDATA[<p>Sorry did not read the conclusion</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ravi</title>
		<link>http://www.gridshore.nl/2009/04/06/the-power-of-immutability-in-a-rich-domain-model/comment-page-1/#comment-20757</link>
		<dc:creator>Ravi</dc:creator>
		<pubDate>Tue, 07 Apr 2009 12:58:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.gridshore.nl/?p=696#comment-20757</guid>
		<description>Nice article. Will hibernate work with a immutable rich domain model ?</description>
		<content:encoded><![CDATA[<p>Nice article. Will hibernate work with a immutable rich domain model ?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

