2008年8月14日星期四

Re: [fw-mvc] Model Validation

I have sent it to Nino's private mail by mistake. Since Nino replied here, I'll provide
the source.

Nino Martincevic wrote:
> > Therefore:
> > Why not use "logical type", like Birthdate, Address, even Username?
> > If you create a logical object for every one of it you can handle
> > all semantic validation and even formatting in one place.
> >
> > So, instead of having to check a date in every model that uses a date
> > you would have to create a Date object and send it to the model, or any
> > other component of your software, if it is validated.

This is not semantic. This date or username doesn't have a meaning yet. You can validate
username sting format or if the username exists in the databaase but it's still
meaningless. It's a generic validator which can be used on all application objects.

Now imagine you have an object representing a student's thesis. This thesis can have
references to different usernames - author, tutor and critic/reviewer. Now, the author,
tutor and critic can't be the same person. This doesn't belong to a generic validator
and should probably be checked at a setter level. Now, the tutors and reviewers need to
have adequate roles or privileges to be used as one. And they have specializations, so a
reviewer of different specialization can't be applied to certain theses.

And that's semantic.

Further, if you write all your validators as separate service objects, no matter how
specialized they are, you will probably end up with anemic data model:

http://www.martinfowler.com/bliki/AnemicDomainModel.html

--
Michał Minicki aka Martel Valgoerad | martel@aie.pl | http://aie.pl/martel.asc
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
"Idleness is not doing nothing. Idleness is being free to do anything." --
Floyd Dell

没有评论: