4

An anemic model is a model without ...

"Anemic domain model is the use of a software domain model where the domain objects contain little or no business logic (validations, calculations, business rules etc.)."

Is a DTO an anemic model without business Logic? And, again, a balie object without its business Logic?

sensorario
  • 20,262
  • 30
  • 97
  • 159
  • 2
    There are two kind of objects. [Data structures and "real" Objects](https://sites.google.com/site/unclebobconsultingllc/active-record-vs-objects#TOC-The-Difference-between-Objects-and-Data-Structures). A DTO is simply a data structure and OO design guidelines do not apply to these. – plalx May 29 '17 at 13:43
  • 1
    I agree with p|a|x. It has to do with the intent. If a data structure is used to transfer data only and the intent is to use it as such then it cannot be classified as "anemic". If the intent is to use such a structure within your domain model it certainly *is* anemic. – Eben Roux May 30 '17 at 06:46
  • 1
    @sensorario https://martinfowler.com/eaaCatalog/dataTransferObject.html (Regarding the remark at 3d paragraph : history since proved Fowler's definition of Value Object right and the "Sun Community's" wrong) – guillaume31 May 31 '17 at 09:20

1 Answers1

5

First of all let's split behavior in two: behavior for read and behavior for write so we speak the same language.

Is a DTO an anemic model without business Logic?

You cannot say that a DTO is anemic or not because a DTO is immutable and anemy makes sense only in the mutating/write side of an architecture (for example the Command side in CQRS) but if we force the term a little the yes, a DTO is anemic and has no behavior (neither read nor write) by definition: "DTO does not have any behavior except for storage and retrieval of its own data".

A Value object has behavior (behavior for read). For example, it implements the behavoir to test if two value objects are equal or not.

To extend the answer a little, Aggregate roots and nested Entities have behavior for the write side (all kinds of validations).

Constantin Galbenu
  • 16,951
  • 3
  • 38
  • 54