<?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: Does Lazy Loading via Properties Violate Domain Driven Design Principles?</title>
	<atom:link href="http://lostechies.com/johnteague/2008/06/02/does-loading-violate-domain-driven-design-principles/feed/" rel="self" type="application/rss+xml" />
	<link>http://lostechies.com/johnteague/2008/06/02/does-loading-violate-domain-driven-design-principles/</link>
	<description></description>
	<lastBuildDate>Wed, 08 May 2013 18:43:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
	<item>
		<title>By: t_moriarty</title>
		<link>http://lostechies.com/johnteague/2008/06/02/does-loading-violate-domain-driven-design-principles/#comment-15</link>
		<dc:creator>t_moriarty</dc:creator>
		<pubDate>Sun, 21 Dec 2008 06:10:53 +0000</pubDate>
		<guid isPermaLink="false">/blogs/johnteague/archive/2008/06/02/does-loading-violate-domain-driven-design-principles.aspx#comment-15</guid>
		<description>Maybe a better example would be:

order.LineItems.Count;

Obviously, it would be quicker to just get count(*) from the db if the list is not yet loaded.</description>
		<content:encoded><![CDATA[<p>Maybe a better example would be:</p>
<p>order.LineItems.Count;</p>
<p>Obviously, it would be quicker to just get count(*) from the db if the list is not yet loaded.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Colin Jack</title>
		<link>http://lostechies.com/johnteague/2008/06/02/does-loading-violate-domain-driven-design-principles/#comment-14</link>
		<dc:creator>Colin Jack</dc:creator>
		<pubDate>Thu, 05 Jun 2008 09:00:45 +0000</pubDate>
		<guid isPermaLink="false">/blogs/johnteague/archive/2008/06/02/does-loading-violate-domain-driven-design-principles.aspx#comment-14</guid>
		<description>Good discussion and I agree with those who think that lazy loading doesn&#039;t violate DDD principles. 

As far as getting the data you need when you need, Udi Dahan had some interesting ideas regarding fetching strategies. Never tried that approach, we just use eager fetching queries when we need them, but you might want to give it a look.

Would an approach where we could explicitly say to a repository, at a high (as in DDD driven) level, give me this aggregate along with these associated aggregates be better?

@Jarod
Totally agree with your point, when you load an aggregate you *should* get the whole thing. I tend to view lazy loading as more useful between aggregate roots though.</description>
		<content:encoded><![CDATA[<p>Good discussion and I agree with those who think that lazy loading doesn&#8217;t violate DDD principles. </p>
<p>As far as getting the data you need when you need, Udi Dahan had some interesting ideas regarding fetching strategies. Never tried that approach, we just use eager fetching queries when we need them, but you might want to give it a look.</p>
<p>Would an approach where we could explicitly say to a repository, at a high (as in DDD driven) level, give me this aggregate along with these associated aggregates be better?</p>
<p>@Jarod<br />
Totally agree with your point, when you load an aggregate you *should* get the whole thing. I tend to view lazy loading as more useful between aggregate roots though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jcteague</title>
		<link>http://lostechies.com/johnteague/2008/06/02/does-loading-violate-domain-driven-design-principles/#comment-13</link>
		<dc:creator>jcteague</dc:creator>
		<pubDate>Wed, 04 Jun 2008 19:15:44 +0000</pubDate>
		<guid isPermaLink="false">/blogs/johnteague/archive/2008/06/02/does-loading-violate-domain-driven-design-principles.aspx#comment-13</guid>
		<description>@

That&#039;s a great perspective.  Not every fetch / db call are created equal.  Use your judgment and design appropriately.

Thanks </description>
		<content:encoded><![CDATA[<p>@</p>
<p>That&#8217;s a great perspective.  Not every fetch / db call are created equal.  Use your judgment and design appropriately.</p>
<p>Thanks </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben Scheirman</title>
		<link>http://lostechies.com/johnteague/2008/06/02/does-loading-violate-domain-driven-design-principles/#comment-12</link>
		<dc:creator>Ben Scheirman</dc:creator>
		<pubDate>Wed, 04 Jun 2008 16:27:43 +0000</pubDate>
		<guid isPermaLink="false">/blogs/johnteague/archive/2008/06/02/does-loading-violate-domain-driven-design-principles.aspx#comment-12</guid>
		<description>I think the answer is exactly what you said... if it&#039;s a potentially expensive operation, don&#039;t put it on a property... instead put it no a method.

While I agree that some things should be very explicit, having persistence concerns leak into your model (AHEM entity framework) is a bad idea.</description>
		<content:encoded><![CDATA[<p>I think the answer is exactly what you said&#8230; if it&#8217;s a potentially expensive operation, don&#8217;t put it on a property&#8230; instead put it no a method.</p>
<p>While I agree that some things should be very explicit, having persistence concerns leak into your model (AHEM entity framework) is a bad idea.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jarod</title>
		<link>http://lostechies.com/johnteague/2008/06/02/does-loading-violate-domain-driven-design-principles/#comment-11</link>
		<dc:creator>Jarod</dc:creator>
		<pubDate>Wed, 04 Jun 2008 14:48:47 +0000</pubDate>
		<guid isPermaLink="false">/blogs/johnteague/archive/2008/06/02/does-loading-violate-domain-driven-design-principles.aspx#comment-11</guid>
		<description>@jcteague

I think your example is great and fits the subject of the post well. Yes, I do think that lazy loading violates DDD concepts. Another principle to consider here is Command-Query-Seperation. (I think?)

IMO, when I hit a repository, I want all the data for that aggregate. I want to be explicit with my query, I want to know exactly what I send to my db and when. If its too much data to get, then I say the aggregate is too big, or I am using the wrong one in context.

I agree with Kerry here, I see LL more and more as bad practice. (There may be some limited scenarios where it is useful)

Lazy loading can be a curse. As with your statement, I used to think it was &#039;sooo cool&#039;, but have since changed my mind. This mainly from working with distributed domains, and in pre-ddd days, working with teams who abuse lazy loading, just walking a graph sending endless queries to the db causing nasty perf issues... its, well, Lazy!</description>
		<content:encoded><![CDATA[<p>@jcteague</p>
<p>I think your example is great and fits the subject of the post well. Yes, I do think that lazy loading violates DDD concepts. Another principle to consider here is Command-Query-Seperation. (I think?)</p>
<p>IMO, when I hit a repository, I want all the data for that aggregate. I want to be explicit with my query, I want to know exactly what I send to my db and when. If its too much data to get, then I say the aggregate is too big, or I am using the wrong one in context.</p>
<p>I agree with Kerry here, I see LL more and more as bad practice. (There may be some limited scenarios where it is useful)</p>
<p>Lazy loading can be a curse. As with your statement, I used to think it was &#8216;sooo cool&#8217;, but have since changed my mind. This mainly from working with distributed domains, and in pre-ddd days, working with teams who abuse lazy loading, just walking a graph sending endless queries to the db causing nasty perf issues&#8230; its, well, Lazy!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jcteague</title>
		<link>http://lostechies.com/johnteague/2008/06/02/does-loading-violate-domain-driven-design-principles/#comment-10</link>
		<dc:creator>jcteague</dc:creator>
		<pubDate>Wed, 04 Jun 2008 13:38:32 +0000</pubDate>
		<guid isPermaLink="false">/blogs/johnteague/archive/2008/06/02/does-loading-violate-domain-driven-design-principles.aspx#comment-10</guid>
		<description>@Sergio

That&#039;s a very good point.  It&#039;s always important to remember we don&#039;t live in a perfect world and using property behavior may be an acceptable tradeof.

Thanks </description>
		<content:encoded><![CDATA[<p>@Sergio</p>
<p>That&#8217;s a very good point.  It&#8217;s always important to remember we don&#8217;t live in a perfect world and using property behavior may be an acceptable tradeof.</p>
<p>Thanks </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kerry</title>
		<link>http://lostechies.com/johnteague/2008/06/02/does-loading-violate-domain-driven-design-principles/#comment-9</link>
		<dc:creator>Kerry</dc:creator>
		<pubDate>Wed, 04 Jun 2008 12:17:50 +0000</pubDate>
		<guid isPermaLink="false">/blogs/johnteague/archive/2008/06/02/does-loading-violate-domain-driven-design-principles.aspx#comment-9</guid>
		<description>I think lazy loading properties in general is a bad practice, if only from the standpoint of reducing transparency in your code.  It doesn&#039;t take any more code to call a repository or other getter to load your collections, and the simple act of doing so ensures that the developer has some awareness of the data operations.

Another consideration is true separation of concerns - if the business rules surrounding the loading of the property change, there is no indication to the consumer of this at all.  Even if the property is lazy-loaded by calling an appropriate repository method, the existing code is still impacted with no indication to the developer that a change has been made.</description>
		<content:encoded><![CDATA[<p>I think lazy loading properties in general is a bad practice, if only from the standpoint of reducing transparency in your code.  It doesn&#8217;t take any more code to call a repository or other getter to load your collections, and the simple act of doing so ensures that the developer has some awareness of the data operations.</p>
<p>Another consideration is true separation of concerns &#8211; if the business rules surrounding the loading of the property change, there is no indication to the consumer of this at all.  Even if the property is lazy-loaded by calling an appropriate repository method, the existing code is still impacted with no indication to the developer that a change has been made.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sergio Pereira</title>
		<link>http://lostechies.com/johnteague/2008/06/02/does-loading-violate-domain-driven-design-principles/#comment-8</link>
		<dc:creator>Sergio Pereira</dc:creator>
		<pubDate>Wed, 04 Jun 2008 12:12:09 +0000</pubDate>
		<guid isPermaLink="false">/blogs/johnteague/archive/2008/06/02/does-loading-violate-domain-driven-design-principles.aspx#comment-8</guid>
		<description>I think replacing the property with a getter is not the answer. That would cause the reverse problem of developers thinking twice or building unnecessary caches to save the result of the method call even when lazy loading is Off. One way or the other the problem will always be that the data access choice made in the mapper will always be obscured by the business object member. I&#039;d say that maybe we are worrying too much about DDD purity.</description>
		<content:encoded><![CDATA[<p>I think replacing the property with a getter is not the answer. That would cause the reverse problem of developers thinking twice or building unnecessary caches to save the result of the method call even when lazy loading is Off. One way or the other the problem will always be that the data access choice made in the mapper will always be obscured by the business object member. I&#8217;d say that maybe we are worrying too much about DDD purity.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jcteague</title>
		<link>http://lostechies.com/johnteague/2008/06/02/does-loading-violate-domain-driven-design-principles/#comment-7</link>
		<dc:creator>jcteague</dc:creator>
		<pubDate>Wed, 04 Jun 2008 03:58:51 +0000</pubDate>
		<guid isPermaLink="false">/blogs/johnteague/archive/2008/06/02/does-loading-violate-domain-driven-design-principles.aspx#comment-7</guid>
		<description>@Jarod
I knew that example was going to come back and bite me :)

I agree with you, it is a poor example and  I knew it as I was writing it.  Please look beyond the specific example and think about how we use Properties to lazy load.  Do you think we are hiding important information from developers by lazy loading a Property?</description>
		<content:encoded><![CDATA[<p>@Jarod<br />
I knew that example was going to come back and bite me <img src='http://lostechies.com/johnteague/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I agree with you, it is a poor example and  I knew it as I was writing it.  Please look beyond the specific example and think about how we use Properties to lazy load.  Do you think we are hiding important information from developers by lazy loading a Property?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jarod</title>
		<link>http://lostechies.com/johnteague/2008/06/02/does-loading-violate-domain-driven-design-principles/#comment-6</link>
		<dc:creator>Jarod</dc:creator>
		<pubDate>Wed, 04 Jun 2008 03:39:01 +0000</pubDate>
		<guid isPermaLink="false">/blogs/johnteague/archive/2008/06/02/does-loading-violate-domain-driven-design-principles.aspx#comment-6</guid>
		<description>I think lazy loading is bad in this context. Since the order is the aggregate root in this scenario, it should load the required data (spans) explicitly to complete the graph (think transaction), in this case line items and maybe products. Were just getting one order right?

IMO, the example above w/lazy loading is a smell the developer is using the wrong aggregate/repository for the job. If the developer doesn&#039;t need the line items at the time, it is likely they are really dealing with a different aggregate, such as Customer.Orders, where the customer repository would not load line items. 

This would become very apparent once you begin to distribute data accross bounded contexts, whether its messages or crud/sync.</description>
		<content:encoded><![CDATA[<p>I think lazy loading is bad in this context. Since the order is the aggregate root in this scenario, it should load the required data (spans) explicitly to complete the graph (think transaction), in this case line items and maybe products. Were just getting one order right?</p>
<p>IMO, the example above w/lazy loading is a smell the developer is using the wrong aggregate/repository for the job. If the developer doesn&#8217;t need the line items at the time, it is likely they are really dealing with a different aggregate, such as Customer.Orders, where the customer repository would not load line items. </p>
<p>This would become very apparent once you begin to distribute data accross bounded contexts, whether its messages or crud/sync.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
