PC Review


Reply
Thread Tools Rate Thread

Architecture Question - Domain Object Validation

 
 
Joseph Ferris
Guest
Posts: n/a
 
      31st Mar 2008
Good day,

I am trying to figure out how to uniformly handle domain objects which
self-validate. I have an interface named IDomainObject that exposes a
public method called Validate(). A lot of the implementation is
fairly straightforward. I do have a couple of scenarios that pose a
bit of a problem, and I was hoping to get some advice from someone who
might have run into a similar issue.

For the example, let us use the CreditCard object, which is part of a
composite class that represents a user signing up on a site and making
a payment. To make it simple, this object has getters and setters for
card number, card type, cardholder name, and expiration date. Some of
the validation rules which could throw an exception would be invalid
card number (InvalidCardNumberException), invalid card type
(InvalidCardTypeException), and expired expiration date
(ExpiredCardExpirationException). (The validation rules are separate
classes implementing an IValidationRule interface outside of the
Domain Object itself.)

The problem is that the business requirements for this object requires
that we have a means to display all of the problems in the UI layer
that exist at the same time, so it is possible to have any combination
of the example exceptions at the point of validation. There is no
problem in testing for all of them, but what would be the cleanest way
to store these? Should there be an Exceptions collection on the
Domain Object or is there some other way to implement this without
creating a one-off hack for the scenario where multiple problems could
exist at once?

I have also thought about having a single "super-exception" for all
things credit card related (and probably still will for type checking
purposes tied to the Domain Object). I just don't want to do
something dodgy like having the exception message list out all of the
problems, since there is a chance that the message in the UI could
change - causing a ripple effect that would force the assembly to be
modified, as well.

Any recommendations would be greatly appreciated! If there is a
better MS group for this, I would be more than happy to post this
there, as well.

Thanks in advance,

Joseph
 
Reply With Quote
 
 
 
 
Joseph Ferris
Guest
Posts: n/a
 
      12th Apr 2008
For anyone that might be interested, what follows is what I came up
with for my implementation. It does appear to work well and handle
the cases that I was worried about.

First, there is a rule collection on each domain object, as derived
from the base class that I defined for my domain objects. The base
class exposes a Validate() method that is overloaded to either take no
parameters, or a single parameter of a custom Rule type. When the
domain objects are populated, in my case with a domain object factory
hybrid, I can attach a predesignated set of rules. Calling Validate()
will run through all of the rules in the order that they were
attached, raising a singular exception for the first failing rule. If
I am looking for more granularity, I can pass rules in an adhoc manner
through the overload and specifically attempt to catch each exception
for a given rule. While this is a little more cumbersome than I was
looking for in a solution, the usage of adhoc validation will most
likely be very limited.

I can extend this approach to come up with some sort of validation
classes that will aggregate the series of individual results to
improve readability, but that would probably be overkill for a 5% (at
best) scenario.

Thanks again,

Joseph

On Mar 31, 11:46*am, Joseph Ferris <joseph.fer...@gmail.com> wrote:
> Good day,
>
> I am trying to figure out how to uniformly handle domain objects which
> self-validate. *I have an interface named IDomainObject that exposes a
> public method called Validate(). *A lot of the implementation is
> fairly straightforward. *I do have a couple of scenarios that pose a
> bit of a problem, and I was hoping to get some advice from someone who
> might have run into a similar issue.
>
> For the example, let us use the CreditCard object, which is part of a
> composite class that represents a user signing up on a site and making
> a payment. *To make it simple, this object has getters and setters for
> card number, card type, cardholder name, and expiration date. *Some of
> the validation rules which could throw an exception would be invalid
> card number (InvalidCardNumberException), invalid card type
> (InvalidCardTypeException), and expired expiration date
> (ExpiredCardExpirationException). *(The validation rules are separate
> classes implementing an IValidationRule interface outside of the
> Domain Object itself.)
>
> The problem is that the business requirements for this object requires
> that we have a means to display all of the problems in the UI layer
> that exist at the same time, so it is possible to have any combination
> of the example exceptions at the point of validation. *There is no
> problem in testing for all of them, but what would be the cleanest way
> to store these? *Should there be an Exceptions collection on the
> Domain Object or is there some other way to implement this without
> creating a one-off hack for the scenario where multiple problems could
> exist at once?
>
> I have also thought about having a single "super-exception" for all
> things credit card related (and probably still will for type checking
> purposes tied to the Domain Object). *I just don't want to do
> something dodgy like having the exception message list out all of the
> problems, since there is a chance that the message in the UI could
> change - causing a ripple effect that would force the assembly to be
> modified, as well.
>
> Any recommendations would be greatly appreciated! *If there is a
> better MS group for this, I would be more than happy to post this
> there, as well.
>
> Thanks in advance,
>
> Joseph


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Good layered architecture with validation and LINQ (+ WCF?) Evert Microsoft Dot NET 10 6th Feb 2008 10:56 AM
Domain Model/Object Design question Froefel Microsoft C# .NET 3 4th Jan 2007 09:33 PM
Validation in a three tier architecture Student Microsoft Dot NET 3 15th Feb 2006 10:51 PM
Validation / Logic Layer architecture djmc Microsoft Dot NET Framework 2 26th Nov 2005 11:44 PM
repost: threading architecture approaches for a shared object, multiple opinions desired Jon Sequeira Microsoft Dot NET 1 23rd Jul 2003 03:58 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:50 PM.