[go: up one dir, main page]

0% found this document useful (0 votes)
10 views22 pages

Implementing Domain Driven Desing With Spring

The document discusses implementing Domain-Driven Design (DDD) using Spring Boot, emphasizing the importance of understanding the domain and creating a rich domain model. It outlines key concepts such as subdomains, ubiquitous language, and the separation of domain models from implementation details. Additionally, it provides practical examples related to library management and highlights best practices for maintaining system consistency and business rules within the DDD framework.

Uploaded by

awsiotsudhakar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views22 pages

Implementing Domain Driven Desing With Spring

The document discusses implementing Domain-Driven Design (DDD) using Spring Boot, emphasizing the importance of understanding the domain and creating a rich domain model. It outlines key concepts such as subdomains, ubiquitous language, and the separation of domain models from implementation details. Additionally, it provides practical examples related to library management and highlights best practices for maintaining system consistency and business rules within the DDD framework.

Uploaded by

awsiotsudhakar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Implementing

Domain Driven Design


with Spring Boot

Maciej Walkowiak | @maciejwalkowiak


DEVELOPING
SOFTWARE
IS HARD
Maciej Walkowiak | @maciejwalkowiak
Eric Evans
Domain-Driven Design is an approach to
Martin Fowler
software development that centers the
development on programming a domain
model that has a rich understanding of
the processes and rules of a domain.
https://martinfowler.com/bliki/DomainDrivenDesign.html
UNDERSTAND THE DOMAIN
SPLIT BIG DOMAIN INTO SUBDOMAINS
DEVELOP AN UBIQUITUS LANGUAGE
DEVELOP A DOMAIN MODEL
SEPARATE DOMAIN MODEL FROM IMPLEMENTATION DETAILS
HTTP Clients
HTTP API
(@HttpExchange,
(Spring MVC,
RestClient,
Spring WebFlux)
OpenFeign)

Messaging
(Kafka, RabbitMQ,
SQS …)

Persistence
(JPA, JDBC,
Business Logic MongoDB
(@Service) …+
@Repository)

Caching
(Redis, Caffeine,
…)

Maciej Walkowiak | @maciejwalkowiak


HTTP Clients
HTTP API (@HttpExchange,
(Spring MVC, RestClient,
Spring WebFlux) OpenFeign)

Business Logic
Persistence
Messaging
(JPA, JDBC,
(Kafka, RabbitMQ,
MongoDB
SQS …)
…)

Caching
(Redis, Caffeine,
…)
Maciej Walkowiak | @maciejwalkowiak
HTTP Clients
HTTP API (@HttpExchange,
(Spring MVC, RestClient,
Spring WebFlux) OpenFeign)

Domain
Model
Persistence
Messaging
(JPA, JDBC,
(Kafka, RabbitMQ,
MongoDB
SQS …)
…)

Caching
(Redis, Caffeine,
…)
Maciej Walkowiak | @maciejwalkowiak
DOMAIN MODEL ENCAPSULATES
DOMAIN KNOWLEDGE,
DOMAIN RULES,
Domain
PROCESSES, CONSTRAINTS, Model

BEHAVIOURS, STATE CHANGES.

Maciej Walkowiak | @maciejwalkowiak


TACTICAL Entities
Value
Objects

DESIGN Repositorie
s
Domain Model
Domain
Services

Aggregates Factories

Maciej Walkowiak | @maciejwalkowiak


https://dev.to/barrymcauley/onion-architecture-3fgl

Maciej Walkowiak | @maciejwalkowiak


As a librarian I want to register a copy of a book available to lend, by
scanning book ISBN and the bar code.

The bar code is printed in the library and pasted on each copy of the
book. Each copy has its own unique bar code.

If the book is not yet in the catalog, it should be added there with
information about the title and ISBN.
As a library user, I want to borrow a copy of
a book. I want to know up until when I can
As a library user, I want to return a copy of hold the book so that I don't pay a fee.
a book I borrowed. If the book is returned
after the return date, user must pay a fee.

To avoid manual work, we are going to use


We learned that there is already another 3rd party service that returns book
company implementing a service that information based on the ISBN code. For
calculates the fee for late returns. Maciej Walkowiak | @maciejwalkowiak
example: https://openlibrary.org/
As a librarian I want to register a copy of a book available to lend, by
scanning book ISBN and the bar code.

The bar code is printed in the library and pasted on each copy of the
book. Each copy has its own unique bar code.

If the book is not yet in the catalog, it should be added there with
information about the title and ISBN.
As a library user, I want to borrow a copy of
a book. I want to know up until when I can
As a library user, I want to return a copy of a
hold the book so that I don't pay a fee.
book I borrowed. If the book is returned
after the return date, user must pay a fee.

To avoid manual work, we are going to use


We learned that there is already another 3rd party service that returns book
company implementing a service that information based on the ISBN code. For
calculates the fee for late returns. Maciej Walkowiak | @maciejwalkowiak
example: https://openlibrary.org/
Let’s code 🔥

Maciej Walkowiak | @maciejwalkowiak


Wrap Up
• Each entity and value object can only exist in valid state
• Ensure system-wide consistency through domain events
published by aggregates
• Business rules, state changes - implemented in entities
• domain services - rules that do not belong to any entity
e r v ic e s
a i n s
n o d om
e r h a p s l ?
P at al
Maciej Walkowiak | @maciejwalkowiak
Wrap Up
• JPA Entity may be a DDD entity (but does not have to)
• Aggregates refer each other by identi er, not by a direct reference
• Model Value Objects with records
• Onion/Hexagonal/Clean Architecture works well with DDD
technical patterns

Maciej Walkowiak | @maciejwalkowiak


fi
Maciej Walkowiak | @maciejwalkowiak
Oliver Drotbohm

Maciej Walkowiak | @maciejwalkowiak


Oliver Drotbohm

Thanks Oliver!

Maciej Walkowiak | @maciejwalkowiak


Thank you!

Maciej Walkowiak | @maciejwalkowiak

You might also like