<?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: Performant and Explicit Domain Models</title>
	<atom:link href="http://www.udidahan.com/2007/06/04/performant-and-explicit-domain-models/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.udidahan.com/2007/06/04/performant-and-explicit-domain-models/</link>
	<description>Enterprise Development Expert &#38; SOA Specialist</description>
	<lastBuildDate>Sat, 11 Feb 2012 15:16:10 -0600</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Nuno Lopes</title>
		<link>http://www.udidahan.com/2007/06/04/performant-and-explicit-domain-models/comment-page-1/#comment-36014</link>
		<dc:creator>Nuno Lopes</dc:creator>
		<pubDate>Fri, 06 Feb 2009 16:57:45 +0000</pubDate>
		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/06/04/performant-and-explicit-domain-models/#comment-36014</guid>
		<description>For completeness of my reasoning above.

There might be a business rule that there &quot;must&quot; be no Customer without at least one order. Ideally we would do:

Customer aCustomer = new Customer(aOrder);

But the approach I gave required that the Customer to be &quot;born&quot; first.

This problem reminds me a riddle: &quot;Who was born first, the chicken or the Egg?&quot;

So how do we validate this? Well we use Validators much the explained in some powerpoint of Udi (where an event is trapped right before the object is to be stored).

Validators very helpfull for invariants. That is rules that once true are required to be true as long as the object exists in the system.

Nuno</description>
		<content:encoded><![CDATA[<p>For completeness of my reasoning above.</p>
<p>There might be a business rule that there &#8220;must&#8221; be no Customer without at least one order. Ideally we would do:</p>
<p>Customer aCustomer = new Customer(aOrder);</p>
<p>But the approach I gave required that the Customer to be &#8220;born&#8221; first.</p>
<p>This problem reminds me a riddle: &#8220;Who was born first, the chicken or the Egg?&#8221;</p>
<p>So how do we validate this? Well we use Validators much the explained in some powerpoint of Udi (where an event is trapped right before the object is to be stored).</p>
<p>Validators very helpfull for invariants. That is rules that once true are required to be true as long as the object exists in the system.</p>
<p>Nuno</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nuno Lopes</title>
		<link>http://www.udidahan.com/2007/06/04/performant-and-explicit-domain-models/comment-page-1/#comment-36012</link>
		<dc:creator>Nuno Lopes</dc:creator>
		<pubDate>Fri, 06 Feb 2009 13:39:47 +0000</pubDate>
		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/06/04/performant-and-explicit-domain-models/#comment-36012</guid>
		<description>By the way I liked the article about Domain Fluence. 

One might argue that this approach is not Domain Fluent, but I can equally argue that it is.

Nuno</description>
		<content:encoded><![CDATA[<p>By the way I liked the article about Domain Fluence. </p>
<p>One might argue that this approach is not Domain Fluent, but I can equally argue that it is.</p>
<p>Nuno</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nuno Lopes</title>
		<link>http://www.udidahan.com/2007/06/04/performant-and-explicit-domain-models/comment-page-1/#comment-36011</link>
		<dc:creator>Nuno Lopes</dc:creator>
		<pubDate>Fri, 06 Feb 2009 13:28:46 +0000</pubDate>
		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/06/04/performant-and-explicit-domain-models/#comment-36011</guid>
		<description>Again late to the party so sorry to bring this up again as I think it is crucial.

Although Bags resolve the problem at hand, and sometimes are necessary, prior to it we have another problem (actually I have been seeing this problem in a lot of examples). 

Again aggregates. We have found more then handful types of aggregations depending on the type of collaboration (Composite-item, Container-item, Group-Member, Party-Transaction, Template-Item, etc etc etc etc etc).

The collaboration pattern of choice have specific rules about who directs what in a collaboration. This in contrast of one recepee fits all for any kind of aggregation (just put add remove in the aggregator and it rules everything about creating its &quot;items&quot;). The problem is that say the object being aggregated (The Order) can also be agregated by some other object at the time of creation (Place?).

For instance:

&quot;A Customer making an Order of products on a Place&quot;.

So who does create the Order? The customer (or its Role) that makes it, or the place (or its Role) that accepts it? 

I know that everyone will say that is the Customer that makes it (good OO). But this question makes sense in a lot contexts (too many).

I&#039;ve found that in situations such as this it is preferable to do something like this on the service:

Order aOrder = new Order(aCustomer, aPlace);
// add products.
tx.Commit. 

Actually I tend to do this everytime except for aggregations that imply ownership ... aka composition (which is different for assembly-part).

An example of this we have right here. The Order and its OrderLines. An Order is Composed by OrderLines. Which is not the case of Customer and Order (A customer is not composed by its orders). In most business cases an Order (Transaction) can last longer then then any info put in the Customer entity as it can change (Name, Delivery Address, Payment etc etc etc should be all be within the Order that can refer the customer for completness but it is not essential).

In my experience, I&#039;ve found also that in most Composite collaborations actually the number of items in the composite (Say Building-Floor-Room, or Organization-Department-Subdepartement) is quite small or hierarchical.

In other words, except for the composites objects usually aggregators don&#039;t create it&#039;s &quot;items&quot;. That is easy to explain to any team member coding the service layer.

So the problem is solved at the Domain Model and OOP practice rather then technology and it becomes natural. Furthermore the technical solution given by Ayende works quite well.

Notice that I&#039;m not proposing that the Customer shouldn&#039;t be able have and provide a list of its Orders, it should. Nevertheless if it is &quot;him&quot; solely governs the list to the point it creates the items in it is another matter.

Does this make sense?

Nuno</description>
		<content:encoded><![CDATA[<p>Again late to the party so sorry to bring this up again as I think it is crucial.</p>
<p>Although Bags resolve the problem at hand, and sometimes are necessary, prior to it we have another problem (actually I have been seeing this problem in a lot of examples). </p>
<p>Again aggregates. We have found more then handful types of aggregations depending on the type of collaboration (Composite-item, Container-item, Group-Member, Party-Transaction, Template-Item, etc etc etc etc etc).</p>
<p>The collaboration pattern of choice have specific rules about who directs what in a collaboration. This in contrast of one recepee fits all for any kind of aggregation (just put add remove in the aggregator and it rules everything about creating its &#8220;items&#8221;). The problem is that say the object being aggregated (The Order) can also be agregated by some other object at the time of creation (Place?).</p>
<p>For instance:</p>
<p>&#8220;A Customer making an Order of products on a Place&#8221;.</p>
<p>So who does create the Order? The customer (or its Role) that makes it, or the place (or its Role) that accepts it? </p>
<p>I know that everyone will say that is the Customer that makes it (good OO). But this question makes sense in a lot contexts (too many).</p>
<p>I&#8217;ve found that in situations such as this it is preferable to do something like this on the service:</p>
<p>Order aOrder = new Order(aCustomer, aPlace);<br />
// add products.<br />
tx.Commit. </p>
<p>Actually I tend to do this everytime except for aggregations that imply ownership &#8230; aka composition (which is different for assembly-part).</p>
<p>An example of this we have right here. The Order and its OrderLines. An Order is Composed by OrderLines. Which is not the case of Customer and Order (A customer is not composed by its orders). In most business cases an Order (Transaction) can last longer then then any info put in the Customer entity as it can change (Name, Delivery Address, Payment etc etc etc should be all be within the Order that can refer the customer for completness but it is not essential).</p>
<p>In my experience, I&#8217;ve found also that in most Composite collaborations actually the number of items in the composite (Say Building-Floor-Room, or Organization-Department-Subdepartement) is quite small or hierarchical.</p>
<p>In other words, except for the composites objects usually aggregators don&#8217;t create it&#8217;s &#8220;items&#8221;. That is easy to explain to any team member coding the service layer.</p>
<p>So the problem is solved at the Domain Model and OOP practice rather then technology and it becomes natural. Furthermore the technical solution given by Ayende works quite well.</p>
<p>Notice that I&#8217;m not proposing that the Customer shouldn&#8217;t be able have and provide a list of its Orders, it should. Nevertheless if it is &#8220;him&#8221; solely governs the list to the point it creates the items in it is another matter.</p>
<p>Does this make sense?</p>
<p>Nuno</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: thesoftwaresimplist</title>
		<link>http://www.udidahan.com/2007/06/04/performant-and-explicit-domain-models/comment-page-1/#comment-10790</link>
		<dc:creator>thesoftwaresimplist</dc:creator>
		<pubDate>Fri, 16 Nov 2007 23:22:44 +0000</pubDate>
		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/06/04/performant-and-explicit-domain-models/#comment-10790</guid>
		<description>Colin,

For testing the correctness of the Domain Model (unit testing), no mocking is done. I test according to interfaces, which may or may not be at the aggregate level. For instance, Orders belong to a Customer, the aggregate - I do test Orders directly.

About encapsulated classes, I test through the external interface - focusing on externally visible effects.

About coordination, Domain Objects can call back into Coordination Layer classes - without depending on them, using events. Does that make sense?</description>
		<content:encoded><![CDATA[<p>Colin,</p>
<p>For testing the correctness of the Domain Model (unit testing), no mocking is done. I test according to interfaces, which may or may not be at the aggregate level. For instance, Orders belong to a Customer, the aggregate &#8211; I do test Orders directly.</p>
<p>About encapsulated classes, I test through the external interface &#8211; focusing on externally visible effects.</p>
<p>About coordination, Domain Objects can call back into Coordination Layer classes &#8211; without depending on them, using events. Does that make sense?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Colin Jack</title>
		<link>http://www.udidahan.com/2007/06/04/performant-and-explicit-domain-models/comment-page-1/#comment-10770</link>
		<dc:creator>Colin Jack</dc:creator>
		<pubDate>Fri, 16 Nov 2007 19:55:38 +0000</pubDate>
		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/06/04/performant-and-explicit-domain-models/#comment-10770</guid>
		<description>Just re-read this post and got this bit:

&quot;When it comes to testing the Domain Model, we don’t have to mock anything out since the Domain Model is independent of all other concerns.&quot;

I agree with you but wondered how you go about it, do you use any mocking at all? Do you test at the aggregate level? What do you do about testing encapsulated classes (e.g. state objects or strategies), do you just test them through the effects they have on the public methods?

Just interested as its a topic thats not discussed enough.

&gt; Personally, I prefer events to coupling the Domain Model to some 
&gt; other Coordination Layer, even if that’s behind some interface, it &gt; forces me to inject that dependency into my Domain Objects. That 
&gt; kind of complexity I don’t want.

I should also say, on the coordination layer front its the coordination layer that calls the domain classes not the other way round. The domain classes only know about other domain classes, not about any layers above or at the same level.</description>
		<content:encoded><![CDATA[<p>Just re-read this post and got this bit:</p>
<p>&#8220;When it comes to testing the Domain Model, we don’t have to mock anything out since the Domain Model is independent of all other concerns.&#8221;</p>
<p>I agree with you but wondered how you go about it, do you use any mocking at all? Do you test at the aggregate level? What do you do about testing encapsulated classes (e.g. state objects or strategies), do you just test them through the effects they have on the public methods?</p>
<p>Just interested as its a topic thats not discussed enough.</p>
<p>&gt; Personally, I prefer events to coupling the Domain Model to some<br />
&gt; other Coordination Layer, even if that’s behind some interface, it &gt; forces me to inject that dependency into my Domain Objects. That<br />
&gt; kind of complexity I don’t want.</p>
<p>I should also say, on the coordination layer front its the coordination layer that calls the domain classes not the other way round. The domain classes only know about other domain classes, not about any layers above or at the same level.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: thesoftwaresimplist</title>
		<link>http://www.udidahan.com/2007/06/04/performant-and-explicit-domain-models/comment-page-1/#comment-2485</link>
		<dc:creator>thesoftwaresimplist</dc:creator>
		<pubDate>Fri, 22 Jun 2007 13:58:20 +0000</pubDate>
		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/06/04/performant-and-explicit-domain-models/#comment-2485</guid>
		<description>Frederik,

I prefer handling &#039;GetOrderTotalForCustomerInPeriod&#039; using the Query Object Pattern, as I wrote about here:

http://udidahan.weblogs.us/2007/03/28/query-objects-vs-methods-on-a-repository/

The necessity comes out of performance. Keeping as much of my logic as possible in the Domain Model has been important for me in terms of testability.

I agree that the issue of using the database as the integration platform creates problems that we may not be able to do away with in one shot. However, I try not to propogate this anti-pattern and phase things out over time. As long as we&#039;re going in the right direction, I&#039;m willing to make some sacrifices on correctness in the short term.

I&#039;m going to be putting an article out in the next month or so on the use of DBs as integration platforms and how that&#039;s changing with SOA. I&#039;d be interested in hearing more about your experiences in that area.</description>
		<content:encoded><![CDATA[<p>Frederik,</p>
<p>I prefer handling &#8216;GetOrderTotalForCustomerInPeriod&#8217; using the Query Object Pattern, as I wrote about here:</p>
<p><a href="http://udidahan.weblogs.us/2007/03/28/query-objects-vs-methods-on-a-repository/" rel="nofollow">http://udidahan.weblogs.us/2007/03/28/query-objects-vs-methods-on-a-repository/</a></p>
<p>The necessity comes out of performance. Keeping as much of my logic as possible in the Domain Model has been important for me in terms of testability.</p>
<p>I agree that the issue of using the database as the integration platform creates problems that we may not be able to do away with in one shot. However, I try not to propogate this anti-pattern and phase things out over time. As long as we&#8217;re going in the right direction, I&#8217;m willing to make some sacrifices on correctness in the short term.</p>
<p>I&#8217;m going to be putting an article out in the next month or so on the use of DBs as integration platforms and how that&#8217;s changing with SOA. I&#8217;d be interested in hearing more about your experiences in that area.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Frederik</title>
		<link>http://www.udidahan.com/2007/06/04/performant-and-explicit-domain-models/comment-page-1/#comment-2476</link>
		<dc:creator>Frederik</dc:creator>
		<pubDate>Fri, 22 Jun 2007 10:04:20 +0000</pubDate>
		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/06/04/performant-and-explicit-domain-models/#comment-2476</guid>
		<description>Hmm, well, then we have a different view on repositories.   In my opinion, they&#039;re part of the Domain and as such, they can contain specialized methods that are required to do some Business Logic. (For Instance &#039;GetOrderTotalForCustomerInPeriod&#039;.   
For me, a repository is more then just a way of retrieving / storing data.

About denormalizing: sometimes this is indeed necessary; however, I do not like to &#039;sacrifice&#039; my DB model just because it is necessary if I want to keep all my logic in the Domain Entities.
Your domain layer might make sure that everything is kept consistent, but it is maybe also possible that other (legacy) applications use the same database.  Then, the consistency is not guaranteed.</description>
		<content:encoded><![CDATA[<p>Hmm, well, then we have a different view on repositories.   In my opinion, they&#8217;re part of the Domain and as such, they can contain specialized methods that are required to do some Business Logic. (For Instance &#8216;GetOrderTotalForCustomerInPeriod&#8217;.<br />
For me, a repository is more then just a way of retrieving / storing data.</p>
<p>About denormalizing: sometimes this is indeed necessary; however, I do not like to &#8217;sacrifice&#8217; my DB model just because it is necessary if I want to keep all my logic in the Domain Entities.<br />
Your domain layer might make sure that everything is kept consistent, but it is maybe also possible that other (legacy) applications use the same database.  Then, the consistency is not guaranteed.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: thesoftwaresimplist</title>
		<link>http://www.udidahan.com/2007/06/04/performant-and-explicit-domain-models/comment-page-1/#comment-2436</link>
		<dc:creator>thesoftwaresimplist</dc:creator>
		<pubDate>Wed, 20 Jun 2007 20:28:09 +0000</pubDate>
		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/06/04/performant-and-explicit-domain-models/#comment-2436</guid>
		<description>Frederik,

&gt; Hmm, why don’t you want to call Repositories from your Domain Entities?

Separation of Concerns - Domain Objects deal with business logic only and know nothing about persistence, and thus are highly testable while Repositories are all about persistence.

&gt; Wouldn’t it then be better to use an injected OrderRepository to get the Orders you’re really interested in to perform this logic out of the persistence store ?

I actually &quot;denormalize&quot; both my Domain Objects and database to handle these kinds of performance requirements. By having the running total of all orders (if that&#039;s what the rules state) as a persistent member on my Customer class, and make sure that value is consistent, I won&#039;t need to iterate. Injecting an OrderRepository wouldn&#039;t solve the performance issue.

Does that make sense?</description>
		<content:encoded><![CDATA[<p>Frederik,</p>
<p>> Hmm, why don’t you want to call Repositories from your Domain Entities?</p>
<p>Separation of Concerns &#8211; Domain Objects deal with business logic only and know nothing about persistence, and thus are highly testable while Repositories are all about persistence.</p>
<p>> Wouldn’t it then be better to use an injected OrderRepository to get the Orders you’re really interested in to perform this logic out of the persistence store ?</p>
<p>I actually &#8220;denormalize&#8221; both my Domain Objects and database to handle these kinds of performance requirements. By having the running total of all orders (if that&#8217;s what the rules state) as a persistent member on my Customer class, and make sure that value is consistent, I won&#8217;t need to iterate. Injecting an OrderRepository wouldn&#8217;t solve the performance issue.</p>
<p>Does that make sense?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Frederik</title>
		<link>http://www.udidahan.com/2007/06/04/performant-and-explicit-domain-models/comment-page-1/#comment-2434</link>
		<dc:creator>Frederik</dc:creator>
		<pubDate>Wed, 20 Jun 2007 19:47:52 +0000</pubDate>
		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/06/04/performant-and-explicit-domain-models/#comment-2434</guid>
		<description>Hmm, why don&#039;t you want to call Repositories from your Domain Entities ? As I read in Evans&#039; book: repositories are first class citizens of the domain layer; they are part of the domain.

I understand that you might have some business logic which decides wether a customer is a gold customer or not, based on the orders that this customer has made, but then, it might be necessary that you iteratoe over all the Orders in the OrderCollection of that Customer.  When this customer has a lot of Orders, this can put a weight on performance.   Wouldn&#039;t it then be better to use an injected OrderRepository to get the Orders you&#039;re really interested in to perform this logic out of the persistence store ?</description>
		<content:encoded><![CDATA[<p>Hmm, why don&#8217;t you want to call Repositories from your Domain Entities ? As I read in Evans&#8217; book: repositories are first class citizens of the domain layer; they are part of the domain.</p>
<p>I understand that you might have some business logic which decides wether a customer is a gold customer or not, based on the orders that this customer has made, but then, it might be necessary that you iteratoe over all the Orders in the OrderCollection of that Customer.  When this customer has a lot of Orders, this can put a weight on performance.   Wouldn&#8217;t it then be better to use an injected OrderRepository to get the Orders you&#8217;re really interested in to perform this logic out of the persistence store ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: thesoftwaresimplist</title>
		<link>http://www.udidahan.com/2007/06/04/performant-and-explicit-domain-models/comment-page-1/#comment-2431</link>
		<dc:creator>thesoftwaresimplist</dc:creator>
		<pubDate>Wed, 20 Jun 2007 16:45:03 +0000</pubDate>
		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/06/04/performant-and-explicit-domain-models/#comment-2431</guid>
		<description>Colin,

&gt; Interesting topic.

Glad you liked it.

&gt; Personally I don’t like the event idea, you only really want there to be one subscriber and they absolutely should be subscribing so events don’t seem to me to be appropriate.

Events / delegates are used to keep the logic about when things need to occur in the Domain Model, while keeping it indpendent of how the wiring occurs. It&#039;s all about dependency management, but you&#039;re entitled to your own taste.

&gt; Equally I don’t like being forced to use relationships from the one end (e.g. Order to Client) just for performance. 

Me neither. That&#039;s why I make use of interfaces for hiding these sorts of implementation details.

&gt; Designing your associations like that is going to result in a mess in some cases, it might work for Order/Customer but in complex cases where the classes are in seperate modules it can be messy. 

I&#039;ve done the multi-module thing and it&#039;s usually doable by using IList of IEntity for holding cross module collections.

&gt; One way I handle this is to have these sorts of calls go through a Coordination layer that will ensue the new Orders are saved.

Personally, I prefer events to coupling the Domain Model to some other Coordination Layer, even if that&#039;s behind some interface, it forces me to inject that dependency into my Domain Objects. That kind of complexity I don&#039;t want.

I think that we can agree to disagree on this one :)</description>
		<content:encoded><![CDATA[<p>Colin,</p>
<p>> Interesting topic.</p>
<p>Glad you liked it.</p>
<p>> Personally I don’t like the event idea, you only really want there to be one subscriber and they absolutely should be subscribing so events don’t seem to me to be appropriate.</p>
<p>Events / delegates are used to keep the logic about when things need to occur in the Domain Model, while keeping it indpendent of how the wiring occurs. It&#8217;s all about dependency management, but you&#8217;re entitled to your own taste.</p>
<p>> Equally I don’t like being forced to use relationships from the one end (e.g. Order to Client) just for performance. </p>
<p>Me neither. That&#8217;s why I make use of interfaces for hiding these sorts of implementation details.</p>
<p>> Designing your associations like that is going to result in a mess in some cases, it might work for Order/Customer but in complex cases where the classes are in seperate modules it can be messy. </p>
<p>I&#8217;ve done the multi-module thing and it&#8217;s usually doable by using IList of IEntity for holding cross module collections.</p>
<p>> One way I handle this is to have these sorts of calls go through a Coordination layer that will ensue the new Orders are saved.</p>
<p>Personally, I prefer events to coupling the Domain Model to some other Coordination Layer, even if that&#8217;s behind some interface, it forces me to inject that dependency into my Domain Objects. That kind of complexity I don&#8217;t want.</p>
<p>I think that we can agree to disagree on this one <img src='http://www.udidahan.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: thesoftwaresimplist</title>
		<link>http://www.udidahan.com/2007/06/04/performant-and-explicit-domain-models/comment-page-1/#comment-2430</link>
		<dc:creator>thesoftwaresimplist</dc:creator>
		<pubDate>Wed, 20 Jun 2007 14:57:48 +0000</pubDate>
		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/06/04/performant-and-explicit-domain-models/#comment-2430</guid>
		<description>Frederik,

&gt; Another thing one might ask is, why should your Customer Entity contain a collection of Order objects ? In which case(s) would it be necessary to have the Orders of a Customer ?

We may have business rules that impact whether the customer is preferred (and thus gets a discount) or not based on some calculation on their order history.

&gt; This means that, whenever you do something with your Customer, you drag all his orders (maybe 1000) with you. 

That was my point - I don&#039;t want to do that. My problem was that even if the collection of orders was lazy loaded, adding a new order would cause all those orders to be loaded. This turns out to be a non-problem with NHibernate &quot;bags&quot; which don&#039;t load when an object is added.

&gt; I decide to not have a collection of (in this example) Orders in my Customer entity. Instead, I opt for a method in my OrderRepository which is called ‘GetAllOrdersForCustomer( Customer c )’. Then, in the cases where I do need the Orders of a particular Customer, I just have to call this method.

Since I implement my business rules within the Domain Model, the problem I have with that is that I don&#039;t want my Domain Objects calling into Repositories. That&#039;s not to say that such a query would not be valuable on its own.

Does that answer your questions?</description>
		<content:encoded><![CDATA[<p>Frederik,</p>
<p>> Another thing one might ask is, why should your Customer Entity contain a collection of Order objects ? In which case(s) would it be necessary to have the Orders of a Customer ?</p>
<p>We may have business rules that impact whether the customer is preferred (and thus gets a discount) or not based on some calculation on their order history.</p>
<p>> This means that, whenever you do something with your Customer, you drag all his orders (maybe 1000) with you. </p>
<p>That was my point &#8211; I don&#8217;t want to do that. My problem was that even if the collection of orders was lazy loaded, adding a new order would cause all those orders to be loaded. This turns out to be a non-problem with NHibernate &#8220;bags&#8221; which don&#8217;t load when an object is added.</p>
<p>> I decide to not have a collection of (in this example) Orders in my Customer entity. Instead, I opt for a method in my OrderRepository which is called ‘GetAllOrdersForCustomer( Customer c )’. Then, in the cases where I do need the Orders of a particular Customer, I just have to call this method.</p>
<p>Since I implement my business rules within the Domain Model, the problem I have with that is that I don&#8217;t want my Domain Objects calling into Repositories. That&#8217;s not to say that such a query would not be valuable on its own.</p>
<p>Does that answer your questions?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Colin Jack</title>
		<link>http://www.udidahan.com/2007/06/04/performant-and-explicit-domain-models/comment-page-1/#comment-2423</link>
		<dc:creator>Colin Jack</dc:creator>
		<pubDate>Wed, 20 Jun 2007 12:09:00 +0000</pubDate>
		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/06/04/performant-and-explicit-domain-models/#comment-2423</guid>
		<description>Interesting topic. Personally I don&#039;t like the event idea, you only really want there to be one subscriber and they absolutely should be subscribing so events don&#039;t seem to me to be appropriate.

Equally I don&#039;t like being forced to use relationships from the one end (e.g. Order to Client) just for performance. Designing your associations like that is going to result in a mess in some cases, it might work for Order/Customer but in complex cases where the classes are in seperate modules it can be messy. I&#039;ve posted about this sort of issue here:

http://colinjack.blogspot.com/2007/03/persistence-ignorance-and-associations.html

One way I handle this is to have these sorts of calls go through a Coordination layer that will ensue the new Orders are saved:

http://colinjack.blogspot.com/2007/02/domain-coordination-layer.html

Having said all that we use bags with NHibernate so it is not really an issue for us.

Any thoughts?</description>
		<content:encoded><![CDATA[<p>Interesting topic. Personally I don&#8217;t like the event idea, you only really want there to be one subscriber and they absolutely should be subscribing so events don&#8217;t seem to me to be appropriate.</p>
<p>Equally I don&#8217;t like being forced to use relationships from the one end (e.g. Order to Client) just for performance. Designing your associations like that is going to result in a mess in some cases, it might work for Order/Customer but in complex cases where the classes are in seperate modules it can be messy. I&#8217;ve posted about this sort of issue here:</p>
<p><a href="http://colinjack.blogspot.com/2007/03/persistence-ignorance-and-associations.html" rel="nofollow">http://colinjack.blogspot.com/2007/03/persistence-ignorance-and-associations.html</a></p>
<p>One way I handle this is to have these sorts of calls go through a Coordination layer that will ensue the new Orders are saved:</p>
<p><a href="http://colinjack.blogspot.com/2007/02/domain-coordination-layer.html" rel="nofollow">http://colinjack.blogspot.com/2007/02/domain-coordination-layer.html</a></p>
<p>Having said all that we use bags with NHibernate so it is not really an issue for us.</p>
<p>Any thoughts?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Frederik</title>
		<link>http://www.udidahan.com/2007/06/04/performant-and-explicit-domain-models/comment-page-1/#comment-2359</link>
		<dc:creator>Frederik</dc:creator>
		<pubDate>Sun, 17 Jun 2007 16:03:25 +0000</pubDate>
		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/06/04/performant-and-explicit-domain-models/#comment-2359</guid>
		<description>Another thing one might ask is, why should your Customer Entity contain a collection of Order objects ? 
This means that, whenever you do something with your Customer, you drag all his orders (maybe 1000) with you.   In which case(s) would it be necessary to have the Orders of a Customer ? In which cases do you want to have an overview of all the Orders of a particular Customer ?
I always ask myself this question in such scenario&#039;s, and very often, I decide to not have a collection of (in this example) Orders in my Customer entity.   Instead, I opt for a method in my OrderRepository which is called &#039;GetAllOrdersForCustomer( Customer c )&#039;.   Then, in the cases where I do need the Orders of a particular Customer, I just have to call this method ...
In my opinion -and in this example- it is far more usefull to know the Customer to which an Order belongs, then to having a collection of Orders in the customer entity.</description>
		<content:encoded><![CDATA[<p>Another thing one might ask is, why should your Customer Entity contain a collection of Order objects ?<br />
This means that, whenever you do something with your Customer, you drag all his orders (maybe 1000) with you.   In which case(s) would it be necessary to have the Orders of a Customer ? In which cases do you want to have an overview of all the Orders of a particular Customer ?<br />
I always ask myself this question in such scenario&#8217;s, and very often, I decide to not have a collection of (in this example) Orders in my Customer entity.   Instead, I opt for a method in my OrderRepository which is called &#8216;GetAllOrdersForCustomer( Customer c )&#8217;.   Then, in the cases where I do need the Orders of a particular Customer, I just have to call this method &#8230;<br />
In my opinion -and in this example- it is far more usefull to know the Customer to which an Order belongs, then to having a collection of Orders in the customer entity.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: thesoftwaresimplist</title>
		<link>http://www.udidahan.com/2007/06/04/performant-and-explicit-domain-models/comment-page-1/#comment-2061</link>
		<dc:creator>thesoftwaresimplist</dc:creator>
		<pubDate>Tue, 05 Jun 2007 04:38:13 +0000</pubDate>
		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/06/04/performant-and-explicit-domain-models/#comment-2061</guid>
		<description>It appears that NHibernate Bags don&#039;t have this drawback:

http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html/performance.html#performance-collections-mostefficentinverse</description>
		<content:encoded><![CDATA[<p>It appears that NHibernate Bags don&#8217;t have this drawback:</p>
<p><a href="http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html/performance.html#performance-collections-mostefficentinverse" rel="nofollow">http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html/performance.html#performance-collections-mostefficentinverse</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>

