Implementing_Domain_Driven_Desing_with_Spring.pdf

AdePutraNurcholikSan 16 views 22 slides Jul 10, 2024
Slide 1
Slide 1 of 22
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22

About This Presentation

testes


Slide Content

Maciej Walkowiak | @maciejwalkowiak
Implementing
Domain Driven Design
with Spring Boot

DEVELOPING
SOFTWARE
IS HARD
Maciej Walkowiak | @maciejwalkowiak

Eric Evans

Domain-Driven Design is an approach to
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
Martin Fowler

UNDERSTAND THE DOMAIN
DEVELOP A DOMAIN MODEL
DEVELOP AN UBIQUITUS LANGUAGE
SEPARATE DOMAIN MODEL FROM IMPLEMENTATION DETAILS
SPLIT BIG DOMAIN INTO SUBDOMAINS

Maciej Walkowiak | @maciejwalkowiak
HTTP API
(Spring MVC,
Spring WebFlux)
Persistence
(JPA, JDBC,
MongoDB
… +
@Repository)
HTTP Clients
(@HttpExchange,
RestClient,
OpenFeign)
Caching
(Redis, Caffeine,
…)
Business Logic
(@Service)
Messaging
(Kafka, RabbitMQ,
SQS …)

Maciej Walkowiak | @maciejwalkowiak
HTTP API
(Spring MVC,
Spring WebFlux)
Persistence
(JPA, JDBC,
MongoDB
…)
HTTP Clients
(@HttpExchange,
RestClient,
OpenFeign)
Caching
(Redis, Caffeine,
…)
Business Logic
Messaging
(Kafka, RabbitMQ,
SQS …)

Maciej Walkowiak | @maciejwalkowiak
HTTP API
(Spring MVC,
Spring WebFlux)
Persistence
(JPA, JDBC,
MongoDB
…)
HTTP Clients
(@HttpExchange,
RestClient,
OpenFeign)
Caching
(Redis, Caffeine,
…)
Domain
Model
Messaging
(Kafka, RabbitMQ,
SQS …)

Maciej Walkowiak | @maciejwalkowiak
Domain
Model
DOMAIN MODEL ENCAPSULATES
DOMAIN KNOWLEDGE,
DOMAIN RULES,
PROCESSES, CONSTRAINTS,
BEHAVIOURS, STATE CHANGES.

Maciej Walkowiak | @maciejwalkowiak
Domain Model
Entities
Value
Objects
Repositorie
s Domain
Services
FactoriesAggregates
TACTICAL
DESIGN

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
hold the book so that I don't pay a fee.As a library user, I want to return a copy of
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
3rd party service that returns book
information based on the ISBN code. For
example: https://openlibrary.org/
We learned that there is already another
company implementing a service that
calculates the fee for late returns.

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
hold the book so that I don't pay a fee.
As a library user, I want to  return a copy of 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
3rd party service that returns book
information based on the ISBN code. For
example: https://openlibrary.org/
We learned that there is already another
company implementing a service that
calculates the fee for late returns.

Maciej Walkowiak | @maciejwalkowiak
Let’s code !

Maciej Walkowiak | @maciejwalkowiak
•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
Wrap Up
Perhaps no domain services
at all?

Maciej Walkowiak | @maciejwalkowiak
•JPA Entity may be a DDD entity (but does not have to)
•Aggregates refer each other by identifier, not by a direct reference
•Model Value Objects with records
•Onion/Hexagonal/Clean Architecture works well with DDD
technical patterns
Wrap Up

Maciej Walkowiak | @maciejwalkowiak

Maciej Walkowiak | @maciejwalkowiak
Oliver Drotbohm

Thanks Oliver!
Maciej Walkowiak | @maciejwalkowiak
Oliver Drotbohm

Maciej Walkowiak | @maciejwalkowiak
Thank you!
Tags