Building Blocks

Entity: an object with conceptual identity. Things that you would write in own database table with generated ID are entities. Customer, Product, Employee, Vehicle, MedicalDevice are entities. Own class in Domain Model and in JPA. One employee is equal only to himself. Has own ID. Mutable objects.

ValueObject: an object without conceptual identity. Things that you would use in database as containers for some values, but not representing something unique. Quanity, Monetary Amount, Has no ID. One amount of 100 Euro is equal to another amount of 100 Euro. Immutable objects.

Service: domain concept that encodes functionality. Stateless. OrderManager, AccountingCalculator. Singletone class that performs some job.

Entities vs ValueObjects

Distinguisching is often domain-dependent

For example, if we build a bank cash storage system, then 100USD bill can be handled as ValueObject. But if we build a coin Auction system, then one 50 Cent coin is not equal to another 50 Cent coin, therefore it is an Entity.

We want to keep less Entities and more ValueObjects

Classification Example

Untitled

Untitled

Value objects:

Bill can be seen as a part of Registration.

Hotel can be seen as a part of Venue

Stay can be seen as a part of Person

→ Identify possible “Clusters” with aggregations (or compositions), one cluster has a central Entity, that contains some ValueObjects

ValueObjects are immutable parts of entities

Summary