User Tools

Site Tools


anti-patterns:anemic_domain_model
no way to compare when less than two revisions

Differences

This shows you the differences between two versions of the page.


anti-patterns:anemic_domain_model [2017-05-29 11:12] (current) – created christian
Line 1: Line 1:
 +====== Anemic Domain Model ======
  
 +===== Alternative Names =====
 +
 +===== Context =====
 +
 +  * [[contexts:Object-Oriented Design]]
 +
 +
 +===== Problem Statement =====
 +A [[patterns:Domain Model]] without behavior
 +
 +===== Description =====
 +In a [[patterns:Domain Model]] the model classes are supposed to have behavior. All the domain logic (validations, calculations, business rules) should be implemented there. In an anemic domain model model classes are mere data containers and all the domain logic is implemented in the service layer. The service layer should normally just coordinate but when the domain model is anemic, it effectively does everything and the domain model is devoid of any behavior. In that sense it's a procedural design in an object-oriented language.
 +
 +===== Causes =====
 +/*how the anti-pattern occurs*/
 +Some frameworks like the old J2EE entity beans encourage having anemic model classes which just have getters and setters. Furthermore [[principles:Uniformity Principle|consistency]] and old habits often lead to anemic models.
 +
 +===== Origin =====
 +/*original source of the anti-pattern description*/
 +{{page>resources:Bliki#reference}} [[https://www.martinfowler.com/bliki/AnemicDomainModel.html|Anemic Domain Model]]
 +
 +===== Disadvantages =====
 +/* reference principle here */
 +  * [[principles:Tell don't Ask/Information Expert]] (Tda/IE): Not following TdA leads to anemic domain models.
 +  * [[principles:More Is More Complex]] (MIMC): Anemic Domain models push logic to the service layer making it big and untidy.
 +
 +===== Advantages =====
 +/* reference principle here */
 +  * [[principles:Uniformity Principle]] (UP), [[principles:Principle of Least Surprise]] (PLS): If the rest of the code does not have real domain models, it's clearer and less surprising to have the model anemic everywhere.
 +
 +
 +===== Refactorings =====
 +  * [[refactorings:Move Method]]
 +
 +===== Anti-Pattern Collections =====
 +
 +
 +===== Examples =====
 +
 +==== Example 1:  ====
 +
 +
 +
 +===== Description Status =====
 +/* Choose one of the following and comment out the rest: */
 +/*[[wiki:Stub]]*/
 +[[wiki:Incomplete]]
 +/*[[wiki:Complete]]*/
 +
 +
 +===== Further Reading =====
 +
 +
 +===== Discussion =====
 +
 +Discuss this wiki article and the anti-pattern on the corresponding [[talk:anti-patterns:Anemic Domain Model|talk page]].
anti-patterns/anemic_domain_model.txt · Last modified: 2017-05-29 11:12 by christian