Domain Driven Design (DDD)

the essence of DDD is profoundly simple: 
  capture the domain model in domain terms, 
  embed the model in the code, 
  and protect it from corruption. 

EvansClassification

https://martinfowler.com/bliki/EvansClassification.html

Entity

Objects that have a distinct identity that runs through time and different representations. You also hear these called "reference objects".

Value Object

Objects that matter only as the combination of their attributes. Two value objects with the same values for all their attributes are considered equal. I also describe value objects in P of EAA.

One important rule to follow is that value objects should be immutable. To change a value (such as my height) you don't change the height object, you replace it with a new one.

One clear division between entities and values is that values override the equality method (and thus hash) while entities usually don't.

Service

A standalone operation within the context of your domain. A Service Object collects one or more services into an object. Typically you will have only one instance of each service object type within your execution context.

Service objects are often implemented by using global variables, class fields (monostates in Robert Martin's terminology) or singletons.

Springboot2 - hexagonal architecture

application layer

domain layer

infrastructure layer

DDD aggregates

An aggregate is a group of business objects which always need to be consistent. Therefore, we save and update aggregates as a whole inside a transaction.

An aggregate root is a class which works as an entry point to our aggregate.

All business operations should go through the root.

Java JPA and DDD

Repository

A Repository mediates between the domain and data mapping layers, acting like an in-memory domain object collection.

Conceptually, a Repository encapsulates the set of objects persisted in a data store and the operations performed over them, providing a more object-oriented view of the persistence layer.

Repositories are classes or components that encapsulate the logic required to access data sources.

DomainDrivenDesign (last edited 2022-10-21 09:13:35 by localhost)