Tudor
Tudor

Reputation: 1181

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?

Upvotes: 4

Views: 2863

Answers (2)

Dennis Traub
Dennis Traub

Reputation: 51654

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.

Upvotes: 6

Ehsan
Ehsan

Reputation: 834

Value Object of domain layer should be in aggregates. but in some cases, VOs are so general as you mentioned. we put those kinds of generic value objects in special module available for all aggregates but we had one bounded context in our project. IMO you can put your Value objects of each bounded context in it's own.

Upvotes: 0

Related Questions