J
Joseph Ferris
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
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