I think that the discussions that Martin Fowler has raised in his post about the 'AnemicDomainModel' are definitely quite interesting, and by all means worth investigation, but I really think it should be taken with a healthy grain of salt. If you find yourself struggling to figure out how to add domain logic to beans/TOs/VOs just because your worried about this concept of Anemic domain objects, you really may just need to take a break and stop listening for a while, and just look at your architecture and see if it feels correct.

I personally don't really like the concept of ActiveRecord, I feel it mixes data tier objects with business objects, which makes changes to persistence implementations more difficult. But if we are to buy this idea that the AnemicDomainModel is an antipattern that we need to fear, then we shy away from the service, domain object, DAO, DGO/ Gateway pattern, which I personally feel is cleaner and far more versatile.

Of course, it took 10 years to come to the point where I felt that the service layer approach works the best for me. Just because it is a hot topic in the CF community certainly does not mean that anyone should blindly adopt this approach either. Do what's best for your company, development team, application, etc...

Just thoughts,

Chris

Chris Scott
[EMAIL PROTECTED]
http://cdscott.blogspot.com/
http://www.coldspringframework.org/

GIF image



On Jun 14, 2006, at 4:40 PM, Cliff Meyers wrote:

I would caution against pulling validation out of the domain model
entirely, since it could lead to Fowler's "Anemic Domain Model"
antipattern:

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

"It's also worth emphasizing that putting behavior into the domain
objects should not contradict the solid approach of using layering to
separate domain logic from persistence and presentation
responsibilities. The logic that should be in a domain object is
domain logic - validations, calculations, business rules - whatever
you like to call it. (There are cases when you make an argument for
putting data source or presentation logic in a domain object, but
that's orthogonal to my view of anemia.)"

Since many validations are commonly re-used I think it might be better
to build a validation library that the domain objects directly
leverage instead of refactoring the code out into separate "validator"
classes.  Fowler talks about the simple but powerful concept of
"Contextual Validation" here:

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

HTH,


-Cliff


On 6/13/06, Peter Bell <[EMAIL PROTECTED]> wrote:
Hi Jason,

Firstly, I agree 100% with "it depends". There is no right answer for all cases. Many applications will never need editing of large collections of
objects, so the bean approach will be the best approach.

Secondly, duh - good point. 1 object and load 2000 times does make a bunch more sense. If I need to do this, at least I now have a better approach!!!

I associate core validations, transformations and calculations with entities (if a user email address is always required, I put that rule in the model).
I also allow for association of validations, transformations and
calculations to specific actions (so a specific form may not require a password or an import may run a custom validation). In that way, unchanging rules are always enforced and context specific rules can easily be managed.

To keep encapsulation, I actually just allow actions to extend the base list of calculations, transformations and/or validations required for a given call, and have entity specific calculation, transformation and validation
cfc's which store the actual methods and extend base calculation,
transformation and validation cfcs so it is easy to find all of the
validation code in a project.

Best of luck with the refactoring - let us know how it works out!

Best Wishes,
Peter

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Jason Daiger
Sent: Tuesday, June 13, 2006 5:19 PM
To: [email protected]
Subject: RE: [CFCDev] Model or View?


>>Only if all of your validation is against single objects or manageably small collections of objects. What happens if you want to import a large
number of >>users - perhaps using an uploaded csv file?

Peter I'd have to agree with your recommendation to remove the validation from the object. However, like most answers to IT questions 'it depends'. Validation w/in an object seems perfectly acceptiable based on the business requirements. As the business requirements expand to include things like a mass data load then it might be necessary to refactor the code and pull the validation out. Until that becomes a requirement, validation w/in the bean
seems like a great place to start.

>>Assuming you implement that using CF (which is still plausible for
>>that
size of data set), how do you
>>validate 2000 email addresses? I've never tried to create a collection
>>of
2000 objects, but I'm guessing it wouldn't perform all that well.

Why would you create 2000 objects? If needed simply create 1 object and then clear and load that 1 object as needed to process the CSV file. That's minimal overhead with the same gain. Also from my experience data imports
almost always have custom rules. You might need to remove validation
completely or partially or not at all which is why I'm proceeding with the plan to move the validation out of the bean and into the separate area.

The biggest learning experience for me from this post is the refactor piece. I'm looking at refactoring 1 portion of my application out but the rest should remain the same and hence remain unchanged. Hopefully it works as
well in practice as it has in my head up to now.

-Jason



-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Peter Bell
Sent: Tuesday, June 13, 2006 3:59 PM
To: [email protected]
Subject: RE: [CFCDev] Model or View?


Nice to see a posting that isn't spam!!!

RADEMAKERS Tanguy said:
- On the one hand, you have a type of format checking that's essentially about type safety, and that operates on single fields. If you have an object
that exposes an "email address" field, you expect that field (if it's
populated) to hold a syntactically valid email address, not just any old string (i.e. an email address is a string, but a string is not an email
address). This kind of checking belongs in an object.

Only if all of your validation is against single objects or manageably small collections of objects. What happens if you want to import a large number of users - perhaps using an uploaded csv file? Assuming you implement that using CF (which is still plausible for that size of data set), how do you validate 2000 email addresses? I've never tried to create a collection of 2000 objects, but I'm guessing it wouldn't perform all that well. That leaves you with duplicating the code in both the object and a service layer. That's the only thing I can't square with building validation into an object - how it handles use cases where you want to deal with larger collections of
data that don't make sense to instantiate as a collection of objects.

As with most things OO, I'm probably missing something obvious :->

Any thoughts?

Best Wishes,
Peter

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of RADEMAKERS Tanguy
Sent: Tuesday, June 13, 2006 1:32 PM
To: [email protected]
Subject: RE: [CFCDev] Model or View?


>What i do, cuz i'm a little intellectually lazy, like Ray, is to place
a validate
>function in my bean. Others abstract the validation to a separate
object, but i
>prefer having it in one package. It's just a little easier for me to
see what's
>going on.

I think there are two different kinds of validation:

- On the one hand, you have a type of format checking that's essentially about type safety, and that operates on single fields. If you have an object
that exposes an "email address" field, you expect that field (if it's
populated) to hold a syntactically valid email address, not just any old string (i.e. an email address is a string, but a string is not an email
address). This kind of checking belongs in an object.

- On the other hand, you have what's commonly referred to as business rules, which can operate on one or more fields. The email address field might be mandatory, or it might be restricted to email addresses from a certain domain, or whatever. This kind of checking belongs outside the object - usually in its own object, which accepts an instance of the object to be
checked as an input parameter.

I think it's a good idea to separate the two this way because business rules tend to be both more changeable over time and can also be context sensitive, whereas type or format checkers tend to be pretty stable. Bob from marketing might change his mind every two weeks as to whether the email field should be mandatory or not, or come up with all kinds of context related exceptions like "normal users can only enter email addresses from the same domain as their email address but administrators can enter email addresses from any
domain, or not enter an email address at all if they want", but what
constitutes a syntactically valid email address is not likely to change that
much.

just my 0.02$
/t



----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to
[email protected] with the words 'unsubscribe cfcdev' as the subject of the
email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting
(www.cfxhosting.com).

An archive of the CFCDev list is available at
www.mail-archive.com/[email protected]





----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to
[email protected] with the words 'unsubscribe cfcdev' as the subject of the
email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting
(www.cfxhosting.com).

An archive of the CFCDev list is available at
www.mail-archive.com/[email protected]





----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to
[email protected] with the words 'unsubscribe cfcdev' as the subject of the
email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting
(www.cfxhosting.com).

An archive of the CFCDev list is available at
www.mail-archive.com/[email protected]





----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to [email protected] with the words 'unsubscribe cfcdev' as the subject of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting (www.cfxhosting.com).

An archive of the CFCDev list is available at www.mail-archive.com/ [email protected]





----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to [email protected] with the words 'unsubscribe cfcdev' as the subject of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting (www.cfxhosting.com).

An archive of the CFCDev list is available at www.mail-archive.com/ [email protected]








Reply via email to