Martin Fowler makes a very good point in his blog entry http://martinfowler.com/bliki/AnemicDomainModel.html about Anemic Domain Models: i.e. you should try to put all your business logic on you domain model objects.
But what about business rules that are hard to check in the domain model? A typical example would be: "the userId of my User domain object should be globally unique". Since the User object is not aware of the database, nor of all other existing User objects, it can't really do this check.
So this leads us to the question: is it ok for such a check to be done by a service object? Or should you refactor your domain model so that there is an object that can perform the check (e.g. a UserManager domain object that keeps track of all existing users)?
Erwin


Reply With Quote