Should domain objects call service methods ?
Inevitably, every few months someone over at DDD ( domain driven design ) mailing list seems to ask the question ..
“Should domain objects call service methods ?” . There are few people who seem to think that domain model should be a pristine place where only rightyworthy get to live (Classes have to earn this right by being an parallel to something in real world) . And there are few others who believe in making concessions to make domain model richer and self contained , and if your domain code is never going to be packaged on its own and used outside of the application for which it was originally designed why make this artificial divide .
The pros and cons to such approach can be breifly summried as ,
- Makes domain model richer by hiding underlying data retrival logic .
- Model objects aren’t serializable .
- May break transactional data access semantics in some cases .
- Calling Methods on Domain models involves overhead of data retrieval which may not be obvious if not documented.
- domain model should be “concerned” only with modeling the business domain.
- May contribute to “Knowledge leak” from domain objects into service laye
- Discussion on spring forum http://forum.springframework.org/archive/index.php/t-9874.html
Filed under: Uncategorized | Leave a Comment