What are Domain Entities and Value Objects?
Domain Entities are Behavior Classes: Actions. Value Objects are State Classes, Data.
Domain Entities and Value Objects are bounded together to create a Representational Model of a Business Process referred to as a Bounded Context.
What is an Entity?
An Entity is a class that has the responsibility to manages access, data transformations and data delivery of requested information from the Value Objects contained within the Bounded Context.
Entities Have Global Identity
Entities are created, consumed and destroyed as a unique representation within the Domain representation of the Business Model.
What is a Value Object?
A Value Object is a class that has the responsibility of holding Data as a collections of related attributes: Properties.
Value Objects Have NO Global Identity
Value Objects are created, cloned and destroyed. Once a Value Object is created it is never changed.
A Value Object can be used in more than one Bounded Context. A good example of this is a list of States in the United States.
The Value Object United States would be cloned and passed to the other Aggregate Roots that requires a States list for its Aggregate Root.
If a different collection data values of a Value Object is required, a new Value Object is simply created, a list of Western United States to reduce the payload of the Value Object.
Domain Entities and Value Objects in Action
Lets see how this works using our above Domain Model.
In the Domain Model we have a Customer Management and a Vendor Management Bounded Context.
The Customer Management Bounded Context:
The Vendor Management Bounded Context:
The Aggregate Root
The two bounded contexts look quite a bit alike. The difference is in the Entities but not the Value Objects.
The same Data Transfer Objects, the DTOs, are used for both Context collection. Only the Attribute Property Data values are different: Vendor Information versus Customer Information.
In-depth Understanding of the Business Model
… Creates Reusable Representations of
…… Domain Data as Value Object Data Types
With this knowledge we can identify common Data Types (DTOs) that can support Value Objects in more than one Bounded Context.
Concluding Thoughts
Entities and Value Objects are at the heart and soul of the Domain Driven Design concept.
The understanding of the Responsibility and Dependency Principle gives the developer the understanding of the value of this architectural structure.
Entities are software objects that contain “Action Verbs” as class methods.
These methods, within the Entities, deliver managed data from the domain data: Value Objects.
Entity Methods manage the current state of the Value Objects.
Value Objects are data structures that have no Domain Identity while Entities always has a Domain Identity.
Entities and Value Objects
compose the contents of the
Domain Bounded Context
Wisdom Pearl # 137 – The Primary Technical Imperative
The Primary Technical Imperative in Software Development
… Is to Manage Software Complexity
…… Always be able to Justify Your Designs Complexity
The following two tabs change content below.
I am a Principal Architect at Liquid Hub in the Philadelphia area specializing in Agile Practices as a Certified Scrum Master (CSM). I use Test Driven Development (TDD) and Acceptance Test Driven Development (ATDD) with Behavior Driven Development (BDD) as my bridge to Agile User Stories Acceptance Criteria in a Domain Driven Design (DDD) implementing true RESTful services
Latest posts by Brad Huett (see all)
- DevOps: A Bridge to Your DevOps Culture - March 25, 2016
- Embracing Test Driven Development (TDD) - March 25, 2016
- DevOps: Delivering Agile Projects - March 25, 2016