Tactical Modeling

Domain odel inside a Bounded Context

In Tactical Modeling, we learn how to decompose the Domain Model, how I distribute my Business Rules into different Objects (Domain Objects) so that I can implement this in Code.

DDD + Clean Architecture

To build the Domain layer (Ex.: Entities layer in Clean Architecture) we use the Tactical Modeling.

Drawing

Domain Model

Is a set of Domain Objects, used to distribute the business complexity.

Domain Objects

Entities

Entities <E> abstract the Independent Business Rules.

They have an Identity and a State that mutates over time.

Identity Generation

Identity can be manually generated in the application like UUID or automatic generated from a Database like Sequences.

Value Objects

Value Objects <VO> also have Independent Business Rules.

However they don't have Identity nor State, they are identified by their value and should be immutable.

Domain Services

Domain Services <DS> do specific tasks from a Domain.

They are stateless and should be used for tasks that don't belong to any Entities or Value Objects.

They are usually used in tasks that involves multiple Domain Objects, but don't specifically belong to them.

Ex.:

  • A method for calculating distance between two Coordenates.

  • A method for generating tokens from an Email.

Aggregates

Aggregates <A> are groupings, or clusters of Domain Objects like Entities and Value Objects, while establishing relationships between them (like Foreign Keys).

Aggregates are relationships at application level, and not necessarily means Database relationships.

Persisting Aggregates (Write)

Reconstructing Aggregates (Read)

Aggregate Root

Aggregate Root <AR> is the Entity that leads the Aggregate.

Repositories

Is an extension of the Domain, and responsible for persisting Aggregates, separating the Domain from Infrastructure.

Repository vs DAO

DAO is table oriented, so it only needs to preserve and respect that. (Table columns, column data types, and so on)

This means that DAO won't check data integrity at business level.

Repositories on the other hand, guarantees that persisted Aggregates are in VALID states. And not just when writing on Database but also when reading from it.

Last updated