Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to put the value objects in the domain layer?

Knowing that value objects represent a description of the domain, this description can be part of many entities in different bounded contexts. For example the FullName value object, this VO can live in a "book aquisition" context as member of a Customer entity , also it may live in a "book management" context as a member of a BookAuthor entity. Knowing that value objects can be used in different parts of the domain, where should value objects be implemented ? Should they have a special layer/module that every bounded context will be using when needed?

like image 951
Tudor Avatar asked Sep 12 '25 11:09

Tudor


1 Answers

Each bounded context should implement its own value objects (and entities, of course), even if this leads to code duplication.

As a rule of thumb code reuse across context boundaries should be avoided. There may be exceptions to this rule but using common libraries with domain-related content will quickly interfere with the independent evolution of the affected domain models.

Note: Dan Bergh Johnsson delivered a great and worthwhile talk called The Power of Value - Power Use of Value Objects in Domain Driven Design at Øredev in 2011.

like image 127
Dennis Traub Avatar answered Sep 15 '25 07:09

Dennis Traub