Comparison
Anaemic domain modelvsGetters and setters
Anaemic domain model
the objects have only fields and accessors, and every rule about them lives in a class ending in Service.
A model that looks object-oriented — a class per concept, carefully named — but holds no behaviour, with all the logic in separate service classes. Fowler named it an anti-pattern because it pays the full cost of the mapping and gets none of the benefit: the data and the rules that protect it are apart, so nothing can enforce an invariant. The honest counter-argument is that for a thin application it is simply a transaction script with more files, and the mistake is claiming it is a domain model.
Full entry →Getters and setters
every field is private with a public pair of methods around it, which is the same as public with more typing.
Methods that read and write a field, generated by habit in most object-oriented codebases. A getter that simply exposes a field and a setter that simply assigns one provide no hiding at all; they only preserve the ability to add behaviour later, which is worth something but far less than the ceremony suggests. A blanket set of them is the surest sign of an anaemic domain model, because it means the behaviour that should be inside the object is somewhere else.
Full entry →