<?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: Validation in a DDD world</title>
	<atom:link href="http://lostechies.com/jimmybogard/2009/02/15/validation-in-a-ddd-world/feed/" rel="self" type="application/rss+xml" />
	<link>http://lostechies.com/jimmybogard/2009/02/15/validation-in-a-ddd-world/</link>
	<description>Strong opinions, weakly held</description>
	<lastBuildDate>Wed, 22 May 2013 13:39: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: JRod</title>
		<link>http://lostechies.com/jimmybogard/2009/02/15/validation-in-a-ddd-world/#comment-1330</link>
		<dc:creator>JRod</dc:creator>
		<pubDate>Thu, 04 Mar 2010 17:48:12 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2009/02/15/validation-in-a-ddd-world.aspx#comment-1330</guid>
		<description>If you are enforcing command query separation so that your domain model only contains behaviors, why wouldn&#039;t you put the validation within each bahavior method? I dont see what is wrong with this. I think each method should be responsible for checking whether that operation can be performed and returning a summary of problems to the caller. Putting it anywhere else seems like your domain objects can be manipulated with no restrictions and possibly put in an invalid state. Does anyone see any downside to this approach?</description>
		<content:encoded><![CDATA[<p>If you are enforcing command query separation so that your domain model only contains behaviors, why wouldn&#8217;t you put the validation within each bahavior method? I dont see what is wrong with this. I think each method should be responsible for checking whether that operation can be performed and returning a summary of problems to the caller. Putting it anywhere else seems like your domain objects can be manipulated with no restrictions and possibly put in an invalid state. Does anyone see any downside to this approach?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Arnis L.</title>
		<link>http://lostechies.com/jimmybogard/2009/02/15/validation-in-a-ddd-world/#comment-1329</link>
		<dc:creator>Arnis L.</dc:creator>
		<pubDate>Fri, 11 Dec 2009 22:24:17 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2009/02/15/validation-in-a-ddd-world.aspx#comment-1329</guid>
		<description>Just ignored this problem all the time. Seemed fine to add it where it was needed.

At least now I&#039;ll know what to say next time someone will ask me this question.</description>
		<content:encoded><![CDATA[<p>Just ignored this problem all the time. Seemed fine to add it where it was needed.</p>
<p>At least now I&#8217;ll know what to say next time someone will ask me this question.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bogardj</title>
		<link>http://lostechies.com/jimmybogard/2009/02/15/validation-in-a-ddd-world/#comment-1328</link>
		<dc:creator>bogardj</dc:creator>
		<pubDate>Wed, 13 May 2009 02:09:20 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2009/02/15/validation-in-a-ddd-world.aspx#comment-1328</guid>
		<description>@k03123

In that case, if Order completely manages the OrderLines, it might belong in Order.  Or, in OrderLine, and Order calls Validate on each order line.  Either way, I&#039;d let the Inappropriate Intimacy smell guide you.</description>
		<content:encoded><![CDATA[<p>@k03123</p>
<p>In that case, if Order completely manages the OrderLines, it might belong in Order.  Or, in OrderLine, and Order calls Validate on each order line.  Either way, I&#8217;d let the Inappropriate Intimacy smell guide you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: k03123</title>
		<link>http://lostechies.com/jimmybogard/2009/02/15/validation-in-a-ddd-world/#comment-1327</link>
		<dc:creator>k03123</dc:creator>
		<pubDate>Wed, 13 May 2009 01:24:33 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2009/02/15/validation-in-a-ddd-world.aspx#comment-1327</guid>
		<description>hi jimmy,

i read your post on validation at http://grabbagoft.blogspot.com/2007/10/entity-validation-with-visitors-and.html. 

i tried to post there and saw this blog and thought this is your new blog. 

anyway, in your example lets say Order has many OrderLines. for an Order to be valid for persistence, all the OrderLines also needs to be valid. now where does the validation of OrderLines belong? 

thanks

</description>
		<content:encoded><![CDATA[<p>hi jimmy,</p>
<p>i read your post on validation at <a href="http://grabbagoft.blogspot.com/2007/10/entity-validation-with-visitors-and.html" rel="nofollow">http://grabbagoft.blogspot.com/2007/10/entity-validation-with-visitors-and.html</a>. </p>
<p>i tried to post there and saw this blog and thought this is your new blog. </p>
<p>anyway, in your example lets say Order has many OrderLines. for an Order to be valid for persistence, all the OrderLines also needs to be valid. now where does the validation of OrderLines belong? </p>
<p>thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: colinjack</title>
		<link>http://lostechies.com/jimmybogard/2009/02/15/validation-in-a-ddd-world/#comment-1326</link>
		<dc:creator>colinjack</dc:creator>
		<pubDate>Mon, 23 Feb 2009 09:39:15 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2009/02/15/validation-in-a-ddd-world.aspx#comment-1326</guid>
		<description>@Jimmy
One question, when you talk about commands are you talking about command objects or command messages? I think its the former.</description>
		<content:encoded><![CDATA[<p>@Jimmy<br />
One question, when you talk about commands are you talking about command objects or command messages? I think its the former.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: colinjack</title>
		<link>http://lostechies.com/jimmybogard/2009/02/15/validation-in-a-ddd-world/#comment-1325</link>
		<dc:creator>colinjack</dc:creator>
		<pubDate>Fri, 20 Feb 2009 11:29:24 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2009/02/15/validation-in-a-ddd-world.aspx#comment-1325</guid>
		<description>Not sure I agree with this post. You describe the validation within the domain as if its an awful idea and the examples you give make it sound ridiculous and not consistent with DDD but I don&#039;t think thats in any way true:


&gt;  If we treat our entities as data holders, we might think to 
&gt; put all of our validation there, in the form of reactive 
&gt; validation, where the entity is allowed to be put into 
&gt; an “invalid” state.

Not sure thats true, if you view your entities as behavioral then you ask them to do X and they tell you whether they are happy with this (bearing in mind their current state).


&gt; If all of your validation is on your entity, why are you even 
&gt; doing the Domain Model pattern in the first place?  
&gt; Validation directly on entities is more suited for CRUD-y 
&gt; applications, where patterns like Active Record are more 
&gt; appropriate.

It definitely wouldn&#039;t/couldn&#039;t all be in your entity, not sure anyone would argue that. I&#039;ve had this discussion with Greg a few times and I see the point and I like the always valid idea but I don&#039;t think its that or you&#039;re doing CRUD and shouldn&#039;t be worried about a domain model. 

&gt; Are we supposed to capture all of this in a single Validate 
&gt; method?  I certainly hope not.

Don&#039;t think anyone would recommend. Entities co-ordinate behavior, they should be kept light so in this case the validation method(s) would at most co-ordinate other objects. So if your Order does go through different states then each state class could have its own validaiton rules.


&gt; If you have to put validation on an entity, make sure you 
&gt; capture the context of what the operation the validation is 
&gt; operating against, likely in the name of the method

Absolutely, but thats the key point...validation is entirely contextual. In some cases validation is an either/or thing, an aggregate is valid or it isn&#039;t. 

However once you get interesting behavior involved its &quot;valid for X&quot;, which is in my view where the always valid approach and the normal approach draw together.


&gt; And that’s where I think we should move towards in terms 
&gt; of validation.  Instead of answering the question, “is this 
&gt; object valid”, try and answer the question, “Can this 
&gt; operation be performed?”.

Absolutely, but thats true whatever approach you take. And one way to help with this is to move behavior into your domain model, including your entities (again though, they probably co-ordinate the behavior rather than containing the code). In that context it becomes &quot;are you prepared to do X, no, OK I&#039;ll report notification of reasons why&quot; and then &quot;do X, oh you&#039;ve told me in no uncertain terms your not happy to participate in that behavior&quot;.


&gt;  In my Command object, I’ll do further business rule 
&gt; validation, where I might need to coordinate between 
&gt; several different entities to determine if this operation can 
&gt; be performed successfully.
&gt; And that’s where I think we should move towards in terms 
&gt; of validation.  Instead of answering the question, “is this 
&gt; object valid”, try and answer the question, “Can this 
&gt; operation be performed?”.

Not sure I like that, that mindset totally turns your entities into data-holders. Absolutely I agree on focussing on behavior, and co-ordinating that behavior, but moving it all into commands...na.


&gt; Because our command objects know answers to all of 
&gt; the “Who, what, why” questions, they are in the best 
&gt; position to perform contextual validation based on the 
&gt; operation the user is trying to execute

If its cross aggregate then I&#039;d use a service (which I assume is similiar enough to be the same idea), if its within the boundaries of a single aggregate then I think the aggregate root itself has all it needs as long as the method you call is correct (&quot;DoX&quot;).</description>
		<content:encoded><![CDATA[<p>Not sure I agree with this post. You describe the validation within the domain as if its an awful idea and the examples you give make it sound ridiculous and not consistent with DDD but I don&#8217;t think thats in any way true:</p>
<p>>  If we treat our entities as data holders, we might think to<br />
> put all of our validation there, in the form of reactive<br />
> validation, where the entity is allowed to be put into<br />
> an “invalid” state.</p>
<p>Not sure thats true, if you view your entities as behavioral then you ask them to do X and they tell you whether they are happy with this (bearing in mind their current state).</p>
<p>> If all of your validation is on your entity, why are you even<br />
> doing the Domain Model pattern in the first place?<br />
> Validation directly on entities is more suited for CRUD-y<br />
> applications, where patterns like Active Record are more<br />
> appropriate.</p>
<p>It definitely wouldn&#8217;t/couldn&#8217;t all be in your entity, not sure anyone would argue that. I&#8217;ve had this discussion with Greg a few times and I see the point and I like the always valid idea but I don&#8217;t think its that or you&#8217;re doing CRUD and shouldn&#8217;t be worried about a domain model. </p>
<p>> Are we supposed to capture all of this in a single Validate<br />
> method?  I certainly hope not.</p>
<p>Don&#8217;t think anyone would recommend. Entities co-ordinate behavior, they should be kept light so in this case the validation method(s) would at most co-ordinate other objects. So if your Order does go through different states then each state class could have its own validaiton rules.</p>
<p>> If you have to put validation on an entity, make sure you<br />
> capture the context of what the operation the validation is<br />
> operating against, likely in the name of the method</p>
<p>Absolutely, but thats the key point&#8230;validation is entirely contextual. In some cases validation is an either/or thing, an aggregate is valid or it isn&#8217;t. </p>
<p>However once you get interesting behavior involved its &#8220;valid for X&#8221;, which is in my view where the always valid approach and the normal approach draw together.</p>
<p>> And that’s where I think we should move towards in terms<br />
> of validation.  Instead of answering the question, “is this<br />
> object valid”, try and answer the question, “Can this<br />
> operation be performed?”.</p>
<p>Absolutely, but thats true whatever approach you take. And one way to help with this is to move behavior into your domain model, including your entities (again though, they probably co-ordinate the behavior rather than containing the code). In that context it becomes &#8220;are you prepared to do X, no, OK I&#8217;ll report notification of reasons why&#8221; and then &#8220;do X, oh you&#8217;ve told me in no uncertain terms your not happy to participate in that behavior&#8221;.</p>
<p>>  In my Command object, I’ll do further business rule<br />
> validation, where I might need to coordinate between<br />
> several different entities to determine if this operation can<br />
> be performed successfully.<br />
> And that’s where I think we should move towards in terms<br />
> of validation.  Instead of answering the question, “is this<br />
> object valid”, try and answer the question, “Can this<br />
> operation be performed?”.</p>
<p>Not sure I like that, that mindset totally turns your entities into data-holders. Absolutely I agree on focussing on behavior, and co-ordinating that behavior, but moving it all into commands&#8230;na.</p>
<p>> Because our command objects know answers to all of<br />
> the “Who, what, why” questions, they are in the best<br />
> position to perform contextual validation based on the<br />
> operation the user is trying to execute</p>
<p>If its cross aggregate then I&#8217;d use a service (which I assume is similiar enough to be the same idea), if its within the boundaries of a single aggregate then I think the aggregate root itself has all it needs as long as the method you call is correct (&#8220;DoX&#8221;).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jon Kruger</title>
		<link>http://lostechies.com/jimmybogard/2009/02/15/validation-in-a-ddd-world/#comment-1324</link>
		<dc:creator>Jon Kruger</dc:creator>
		<pubDate>Wed, 18 Feb 2009 22:52:13 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2009/02/15/validation-in-a-ddd-world.aspx#comment-1324</guid>
		<description>I&#039;m not sure I see why it&#039;s such a bad thing to have validation in the entity objects.  

I&#039;ve worked on a bunch of thick client apps.  In these apps, the user can change data in numerous different places, as opposed to a web app where you&#039;re going to call a controller method or post to a page, etc.  

Even in a web app (let&#039;s say I&#039;m using an MVC framework), if I put my validation in my controller action methods, it&#039;s possible that more than one controller could edit the same entity object and that I could need to put the same validation logic in more than one place.  In some cases, I can see why the controller validation method makes sense.

I&#039;ve always done the IsValid() on the entity that throws an exception when IsValid() determines that the entity is not valid.  I&#039;m open to other ways, but I haven&#039;t seen anything else yet.  I&#039;ve done the IValidator&lt;T&gt; thing that another commenter mentioned, although I don&#039;t totally see what I gain from doing it that way (at least for 95% of validation situations).

If you have a better way than the way I&#039;m doing it, I&#039;d be interested in that post and specifically why you did it a certain way.</description>
		<content:encoded><![CDATA[<p>I&#8217;m not sure I see why it&#8217;s such a bad thing to have validation in the entity objects.  </p>
<p>I&#8217;ve worked on a bunch of thick client apps.  In these apps, the user can change data in numerous different places, as opposed to a web app where you&#8217;re going to call a controller method or post to a page, etc.  </p>
<p>Even in a web app (let&#8217;s say I&#8217;m using an MVC framework), if I put my validation in my controller action methods, it&#8217;s possible that more than one controller could edit the same entity object and that I could need to put the same validation logic in more than one place.  In some cases, I can see why the controller validation method makes sense.</p>
<p>I&#8217;ve always done the IsValid() on the entity that throws an exception when IsValid() determines that the entity is not valid.  I&#8217;m open to other ways, but I haven&#8217;t seen anything else yet.  I&#8217;ve done the IValidator<t> thing that another commenter mentioned, although I don&#8217;t totally see what I gain from doing it that way (at least for 95% of validation situations).</p>
<p>If you have a better way than the way I&#8217;m doing it, I&#8217;d be interested in that post and specifically why you did it a certain way.</t></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Justin Rudd</title>
		<link>http://lostechies.com/jimmybogard/2009/02/15/validation-in-a-ddd-world/#comment-1323</link>
		<dc:creator>Justin Rudd</dc:creator>
		<pubDate>Wed, 18 Feb 2009 19:42:01 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2009/02/15/validation-in-a-ddd-world.aspx#comment-1323</guid>
		<description>@bogardj,

How do you get the OperationResult back to the application service?  Return it from the domain method?  That doesn&#039;t seem likely as you&#039;d be constraining your domain model.  Is it similar to what Udi defines in his &quot;domain events&quot;?</description>
		<content:encoded><![CDATA[<p>@bogardj,</p>
<p>How do you get the OperationResult back to the application service?  Return it from the domain method?  That doesn&#8217;t seem likely as you&#8217;d be constraining your domain model.  Is it similar to what Udi defines in his &#8220;domain events&#8221;?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bogardj</title>
		<link>http://lostechies.com/jimmybogard/2009/02/15/validation-in-a-ddd-world/#comment-1322</link>
		<dc:creator>bogardj</dc:creator>
		<pubDate>Wed, 18 Feb 2009 19:04:01 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2009/02/15/validation-in-a-ddd-world.aspx#comment-1322</guid>
		<description>@Justin

OperationResult is just for us a result of an operation.  It has a Success property and an ErrorMessages property, as well contextual information.</description>
		<content:encoded><![CDATA[<p>@Justin</p>
<p>OperationResult is just for us a result of an operation.  It has a Success property and an ErrorMessages property, as well contextual information.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Justin Rudd</title>
		<link>http://lostechies.com/jimmybogard/2009/02/15/validation-in-a-ddd-world/#comment-1321</link>
		<dc:creator>Justin Rudd</dc:creator>
		<pubDate>Wed, 18 Feb 2009 17:41:52 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2009/02/15/validation-in-a-ddd-world.aspx#comment-1321</guid>
		<description>Hey Jimmy,

I&#039;ve been trying to wrap my head around the validation concept.  

For example, I&#039;m working on a system right now that tracks build numbers on products.  I have a business rule that states numbers can&#039;t go backwards.  For example, I have product A which is version 1.  Bob goes and makes it version 3.  Alice comes along and tries to make it version 2.  In my mind, this is clearly a business rule that belongs in the entity representing the product.  But I need to communicate with Alice that she tried to &quot;move backwards&quot;.

Right now, the product entity simply throws an exception.  My application service knows how to handle that exception.  But this feels like using an exception for flow control which is a huge smell to me.

I&#039;ve seen mentioned in several places a &quot;Result&quot; object.  Is this basically a local context object that collects data as the domain is executed?</description>
		<content:encoded><![CDATA[<p>Hey Jimmy,</p>
<p>I&#8217;ve been trying to wrap my head around the validation concept.  </p>
<p>For example, I&#8217;m working on a system right now that tracks build numbers on products.  I have a business rule that states numbers can&#8217;t go backwards.  For example, I have product A which is version 1.  Bob goes and makes it version 3.  Alice comes along and tries to make it version 2.  In my mind, this is clearly a business rule that belongs in the entity representing the product.  But I need to communicate with Alice that she tried to &#8220;move backwards&#8221;.</p>
<p>Right now, the product entity simply throws an exception.  My application service knows how to handle that exception.  But this feels like using an exception for flow control which is a huge smell to me.</p>
<p>I&#8217;ve seen mentioned in several places a &#8220;Result&#8221; object.  Is this basically a local context object that collects data as the domain is executed?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
