Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

DEVELOPING SOFTWARE IS HARD Maciej Walkowiak | @maciejwalkowiak

Slide 3

Slide 3 text

Eric Evans

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

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 …)

Slide 9

Slide 9 text

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 …)

Slide 10

Slide 10 text

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 …)

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

Maciej Walkowiak | @maciejwalkowiak https://dev.to/barrymcauley/onion-architecture-3fgl

Slide 14

Slide 14 text

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.

Slide 15

Slide 15 text

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.

Slide 16

Slide 16 text

Maciej Walkowiak | @maciejwalkowiak Let’s code 🔥

Slide 17

Slide 17 text

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?

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

Maciej Walkowiak | @maciejwalkowiak

Slide 20

Slide 20 text

Maciej Walkowiak | @maciejwalkowiak Oliver Drotbohm

Slide 21

Slide 21 text

Thanks Oliver! Maciej Walkowiak | @maciejwalkowiak Oliver Drotbohm

Slide 22

Slide 22 text

Maciej Walkowiak | @maciejwalkowiak Thank you!