Domain Driven Design
- An approach to software development
- focuses on modeling complex business domains
- aligning software design with business logic.
Core Principles
- Focus on the Domain
- Understand the business problem, not just the technical implementation.
- Collaborate closely with domain experts (stakeholders, business analysts).
- Ubiquitous Language
- Use shared language between developers and domain experts.
- Terms used in code should match business terminology.
- Bounded Contexts
- A logical boundary where a particular model applies.
- Different parts of the system may have different models.
- Modeling the Domain
- Represent the real-world business rules, entities, and processes in code
Development flow:
- Define the domain.
- Define the Ubiquitous Language. (Dictionary)
- List the Nouns (Entities/Values) and Verbs (Actions) that are essential for this system
- Pick the Aggregate Root. ("boss" object that controls consistency)
- When some event happen, always access this.
- Create the Aggregate Root Model class.
- Not using JPA annotation. (
@Table, @Column, @Id)
- No lombok (except for @AllArgsConstructor).
- No created_at, update_at.
- Still use UUID.
- One field is referencing child entity id.
- Set getter if needed.
- final for the fields.
- Add the behaviour in Aggregate Root.
- Create Factory method for Aggregate Root.
- Create Repository.
- Do NOT extend JpaRepository or CrudRepository
- Do NOT use any Spring annotations (@Repository) here.
- Go to infrastructure folder, create Aggregate Root entity class, ****which is entity version.
- Use JPA annotation. (
@Table, @Column, @Id)
- Use lombok (except for @AllArgsConstructor).
- Use created_at, update_at.