Search the web
Sign In
New User? Sign Up
domaindrivendesign · Domain-Driven Design
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Hear how Yahoo! Groups has changed the lives of others. Take me there.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Dealing with exceptions and validation in DDD   Message List  
Reply | Forward Message #3595 of 16115 |
Re: [domaindrivendesign] Dealing with exceptions and validation in DDD

 

Hi,

 

I was wondering if anyone had anymore thoughts about validation.

 

I've been enhancing the domain model from POJOs in Action to do more sophisticated validation and return multiple errors. Instead of throwing an exception when the first error is detected the code now returns a collection of errors in a Notification.

 

For example, the business logic for processing the delivery information for an order has to verify two things:

  1. The delivery time is one hour in the future
  2. The delivery time and address is served by can at least one restaurant

Several things can be wrong:

·         Delivery time is not far enough in the future

·         No restaurants serve the delivery address

·         No restaurants serve the delivery time

·         No restaurants serve the combination of delivery time and address

The domain logic now accumulates these errors in a Notification.

 

One observation I would make is doing more elaborate validation makes the code more complicated – not surprising since its doing more. E.g. there is additional code to figure out whether it's the delivery time or delivery address are wrong. The Notification also has to be passed around between domain objects, e.g. from the PlaceOrderService, which ultimately returns it to the client, to the PendingOrder to the DeliveryInfo.

 

Much of the validation logic is currently in the DeliveryInfo class, which has a validate() method:

 

class DeliveryInfo {

  private Address deliveryAddress;

  private Date deliveryTime;

 

 void validate(Notification, RestaurantRepository) {

  ….

 }

 

}

 

The validate() method checks that the delivery time is in the future and calls RestaurantRepository to determine whether the deliveryInfo is served by any restaurants. I suppose that I could, instead, have a separate DeliveryInfoValidator class.

 

Any thoughts?

 

Chris


--
Enterprise POJO consulting - http://www.chrisrichardson.net
Author, POJOs in Action - http://www.manning.com/crichardson
Enterprise POJOs blog - http://chris-richardson.blog-city.com


 
On 1/30/06, Cliff Meyers <cliff.meyers@...> wrote:
I am working up an application's domain model right now and basically
have the "anemic" domain model built which is just a whole ton of
simple Beans that meet the data requirements of the application.  I am
about embark on building in the business logic to the model... the
tough part :)

Originally I figured that when something happened in the system that
wasn't allowed, it could simply throw a custom exception that extends
RuntimeException which I could then catch and handle appropriately in
another layer if need be.  Unfortunately I don't think this is very
practical for a web application, say where the user submits a form and
has several errors that you want to notify them of at once.

I've been looking at Spring, its Validator interface and some of the
other associated classes but it looks as though they're geared more
towards working in the Controller layer, very far away from my domain
model.  This of course seems contrary to the fundamental spirit of
DDD.  I understand that form validation is a concern that's largely
orthogonal to DDD, but I'm curious how others have modeled exceptions
in their business logic and how they tie that in to a web form
validation framework.

Thanks in advance for any input!


-Cliff



Yahoo! Groups Links

<*> To visit your group on the web, go to:
   http://groups.yahoo.com/group/domaindrivendesign/

<*> To unsubscribe from this group, send an email to:
   domaindrivendesign-unsubscribe@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
   http://docs.yahoo.com/info/terms/






Mon Mar 13, 2006 9:26 pm

cer
Online Now Online Now
Send Email Send Email

Forward
Message #3595 of 16115 |
Expand Messages Author Sort by Date

I am working up an application's domain model right now and basically have the "anemic" domain model built which is just a whole ton of simple Beans that meet...
Cliff Meyers
fenris6644
Offline Send Email
Jan 30, 2006
3:49 pm

I personally use a set of defined rule classes ... The domain class has rules associated to it, there is a method which can be called which will return a...
gregory young
gumboismadeo...
Offline Send Email
Jan 30, 2006
4:00 pm

Take a look at the Nofitication pattern from Martin Fowler. http://www.martinfowler.com/eaaDev/Notification.html _____ From: domaindrivendesign@yahoogroups.com...
Jeff Lowe
jefflowe7
Offline Send Email
Jan 30, 2006
4:34 pm

Assume there's statement like this: "social security numbers have the format xxx-xx-xxxx". Two questions arises to me. 1. How to enforce above rule in all...
m_alanliu
Offline Send Email
Jan 30, 2006
7:32 pm

From: "m_alanliu" <malanliu.at.gmail.com@...> To: "domaindrivendesign@yahoogroups.com" ...
yahoogroups@...
jhrothjr
Offline Send Email
Jan 30, 2006
8:32 pm

... validation in ... This is a valuable point. It is another option we can use in our future design. I have a question. I would like to know how you do it....
m_alanliu
Offline Send Email
Jan 30, 2006
11:14 pm

From: "m_alanliu" <malanliu.at.gmail.com@...> To: "domaindrivendesign@yahoogroups.com" ...
yahoogroups@...
jhrothjr
Offline Send Email
Jan 31, 2006
12:11 am

Value objects are a good way to create validated values (checking once), and then passing them along. But that is simple attribute valuation. There may be...
Rebecca Wirfs-Brock
rebeccawb
Offline Send Email
Jan 31, 2006
12:41 am

Hi, I was wondering if anyone had anymore thoughts about validation. I've been enhancing the domain model from POJOs in Action to do more sophisticated...
Chris Richardson
cer
Online Now Send Email
Mar 13, 2006
9:26 pm

I encountered a similar problem where I have to pass around error collection. The problem is that it looks ugly when you pass error collection as a parameter...
v c
cilativ
Offline Send Email
Mar 13, 2006
11:13 pm

I second Victor. Anything that has to get passed around to every method call, can be treated as a crosscutting concern that should not really be part of the...
Karthik N
karthik_nar
Offline Send Email
Mar 14, 2006
3:07 am

As an alternative, couldn't you just make your Notification object a subclass of RuntimeException (or the equivalent in C#) and throw it up to the appropriate...
Cliff Meyers
fenris6644
Offline Send Email
Mar 14, 2006
3:42 am

... For example, the business logic for processing the delivery information for ... Hi Chris, and first of all thanks for your book ;) These are my thoughts...
Sergio Bossa
sergio_bossa
Offline Send Email
Mar 14, 2006
9:06 am

Chris, If I'm polluting this thread with such a question, we can start a new one. As an aside to all of this, I have a question. In DDD terms, it would be much...
Karthik N
karthik_nar
Offline Send Email
Mar 14, 2006
10:38 am

Hi, Five years ago, I used something similar in user interface programming. If the business method is DeliveryInfo.placeDelivery ( Address, Date), I added...
Tomas Karlsson
marcellus874
Offline Send Email
Mar 15, 2006
5:27 pm

Hi all, I've commented on this argument in my blog, here: http://sbtourist.blogspot.com/2006/03/notification-strategy-for-business.html I'd like to have your...
Sergio Bossa
sergio_bossa
Offline Send Email
Mar 15, 2006
10:21 pm

How do you deal with warnings and informational messages? You don't want to stop processing, you want to accumulate all these messages and display them all in...
v c
cilativ
Offline Send Email
Mar 15, 2006
11:19 pm

... My proposal was to manage business errors, I didn't considered managing informational messages. However, you are right, I should do ... In addition your...
Sergio Bossa
sergio_bossa
Offline Send Email
Mar 15, 2006
11:30 pm

I worked on a project for an international cruising company and had a lot of problems with badly implemented notifications (my fault). I would give it much...
v c
cilativ
Offline Send Email
Mar 15, 2006
11:48 pm

I wonder if there is a better way to handle the verification of specifications. There is currently an internal state associated with each specification and...
Dmitri Dolguikh
witlessbird@...
Send Email
Mar 16, 2006
1:40 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help