Slide 1

Slide 1 text

So you want to be a DDD practitioner

Slide 2

Slide 2 text

Talysson Oliveira Software architect & Chief Learning Officer at Codeminer42 @talyssonoc talysson.com

Slide 3

Slide 3 text

codeminer42.com ai.codeminer42.com @codeminer42

Slide 4

Slide 4 text

dddbrasil.com.br linkedin.com/company/dddbrasil youtube.com/@ddd-brasil

Slide 5

Slide 5 text

There is a lot of misunderstandings around Domain-Driven Design

Slide 6

Slide 6 text

- DDD only adds unnecessary complexity - DDD is a type of software architecture - DDD is a way to organize files and folders - DDD applications have too many files - You have to use a lot of design patterns - DDD makes the code harder to understand - "I never needed DDD for my software to work!" - …

Slide 7

Slide 7 text

"All you need to know about DDD" or "DDD lite" tutorials that skip all the important parts

Slide 8

Slide 8 text

Forget everything you know about DDD for a second

Slide 9

Slide 9 text

Also, stop relating DDD to code

Slide 10

Slide 10 text

To practice DDD, you have to know what it's all about

Slide 11

Slide 11 text

"The heart of software is its ability to solve domain related problems for the user" Domain-Driven Design - Eric Evans

Slide 12

Slide 12 text

Domain - Finance - Health - Education - Shopping - Manufacturing - Mining - Cargo - … Problem "A system of abstractions that describes selected aspects of a domain and can be used to solve problems related to that domain" Model

Slide 13

Slide 13 text

Model Car industry Car sales Car Customer Order Payment Customisations Financing terms Colour Extras …

Slide 14

Slide 14 text

How are domain models cultivated?

Slide 15

Slide 15 text

Domain experts Technical experts (developers, designers, …)

Slide 16

Slide 16 text

Domain experts Technical experts (developers, designers, …)

Slide 17

Slide 17 text

Domain experts Technical experts (developers, designers, …) Model

Slide 18

Slide 18 text

Domain experts Technical experts (developers, designers, …) Ubiquitous language Model

Slide 19

Slide 19 text

DDD is a development approach where: - Focus on the core domain - Explore models in creative collaboration - Speak a ubiquitous language

Slide 20

Slide 20 text

Are the model and the ubiquitous language universal? No (at least not most of the time)

Slide 21

Slide 21 text

Car

Slide 22

Slide 22 text

Product

Slide 23

Slide 23 text

A model and its ubiquitous language are bounded by a context

Slide 24

Slide 24 text

Projects can have multiple models in play at the same time

Slide 25

Slide 25 text

Projects can have multiple contexts in play at the same time

Slide 26

Slide 26 text

Bounded context A boundary within which a model and a ubiquitous language apply

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

Context mapping - Discover the relationships between the contexts - How they share/hide information and influence each other - They place constraints on the nature of the models and pace of change - Contexts that depend on each other mutually (partnership) - Contexts that need to support multiple dependent contexts (open host service) - Contexts that depend unilaterally of some context (conformist) - Contexts that don't even need to know about each other (separate ways) - … - Sometimes you have no control over that relationship! - e.g.: a 3rd party payment processor system

Slide 29

Slide 29 text

DDD is not about code

Slide 30

Slide 30 text

Source:

Slide 31

Slide 31 text

DDD is about communication and knowledge management

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

Strategic design

Slide 34

Slide 34 text

Strategic design

Slide 35

Slide 35 text

Please, do not think DDD is only what we're going to talk from now on ⚠

Slide 36

Slide 36 text

We'll talk about code

Slide 37

Slide 37 text

Model A system of abstractions that describes selected aspects of a domain and can be used to solve problems related to that domain

Slide 38

Slide 38 text

Model-driven design An explanation by example

Slide 39

Slide 39 text

id status shippingAddress estimatedDelivery Order

Slide 40

Slide 40 text

id: 42 status: pending shippingAddress: ABC St. estimatedDelivery: 10/10/2026 Order #42 t

Slide 41

Slide 41 text

id: 42 status: pending shippingAddress: ABC St. estimatedDelivery: 10/10/2026 id: 42 status: pending shippingAddress: XYZ Hwy. estimatedDelivery: 10/10/2026 Order #42 t

Slide 42

Slide 42 text

id: 42 status: pending shippingAddress: ABC St. estimatedDelivery: 10/10/2026 id: 42 status: shipped shippingAddress: Av. XYZ estimatedDelivery: 11/11/2026 Order #42 t id: 42 status: pending shippingAddress: XYZ Hwy. estimatedDelivery: 10/10/2026

Slide 43

Slide 43 text

id: 42 status: pending shippingAddress: ABC St. estimatedDelivery: 10/10/2026 id: 42 status: shipped shippingAddress: Av. XYZ estimatedDelivery: 11/11/2026 Order #42 t id: 42 status: pending shippingAddress: XYZ Hwy. estimatedDelivery: 10/10/2026 Identity + life cycle = Entity In your model

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

red green blue Colour

Slide 46

Slide 46 text

red: 255 green: 0 blue: 0 Red red: 255 green: 0 blue: 255 Pink red: 110 green: 200 blue: 80 Green

Slide 47

Slide 47 text

red: 255 green: 0 blue: 0 Red red: 255 green: 0 blue: 255 Pink red: 110 green: 200 blue: 80 Green No conceptual identity + significance comes from describing things = Value object In your model

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

id status shippingAddress estimatedDelivery Order colour carId tires Customisations airConditioner mediaPlayer Extras paymentMethod totalPrice Payment

Slide 50

Slide 50 text

id status shippingAddress estimatedDelivery Order colour carId tires Customisations airConditioner mediaPlayer Extras paymentMethod totalPrice Payment

Slide 51

Slide 51 text

id status shippingAddress estimatedDelivery Order colour carId tires Customisations airConditioner mediaPlayer Extras paymentMethod totalPrice Payment

Slide 52

Slide 52 text

id status shippingAddress estimatedDelivery Order colour carId tires Customisations airConditioner mediaPlayer Extras paymentMethod totalPrice Payment OtherObject

Slide 53

Slide 53 text

id status shippingAddress estimatedDelivery Order colour carId tires Customisations airConditioner mediaPlayer Extras paymentMethod totalPrice Payment Root entity + conceptual consistency boundary = Aggregate Aggregate root In your model OtherObject

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

"Should be an aggregate, an entity or a value object?"

Slide 56

Slide 56 text

"Should be an aggregate, an entity or a value object?" It depends

Slide 57

Slide 57 text

"Should be an aggregate, an entity or a value object?" on the model It depends — Some DDD practitioner, probably

Slide 58

Slide 58 text

find order by id find orders by status persist an order Order (aggregate)

Slide 59

Slide 59 text

find order by id find orders by status Persistence actions needed by the domain persist an order Order (aggregate)

Slide 60

Slide 60 text

find order by id find orders by status Persistence actions needed by the domain Aggregates that need direct access + set of persistence actions needed by the domain = Repository persist an order Order (aggregate)

Slide 61

Slide 61 text

= Repository OrderRepository + findById(id) + findAllByStatus(status) + store(order) Aggregates that need direct access + set of persistence actions needed by the domain

Slide 62

Slide 62 text

Domain Infrastructure

Slide 63

Slide 63 text

What if a responsibility from the model doesn't naturally fit an entity, aggregate or value object?

Slide 64

Slide 64 text

"Sometimes, it just isn't a thing" Domain-Driven Design - Eric Evans

Slide 65

Slide 65 text

Order (aggregate) Customer (aggregate) FinancingTerms (value object) Financing a car MonthlyPayment (value object)

Slide 66

Slide 66 text

Order (aggregate) Customer (aggregate) FinancingTerms (value object) Financing a car ? MonthlyPayment (value object)

Slide 67

Slide 67 text

Order (aggregate) Customer (aggregate) FinancingTerms (value object) Financing a car MonthlyPayment (value object) FinancingQuoteService ⇒ = Domain service Operation that stands alone in the model, without encapsulating state

Slide 68

Slide 68 text

Strategic design

Slide 69

Slide 69 text

Strategic design Tactical design

Slide 70

Slide 70 text

Combine strategic and tactical design!

Slide 71

Slide 71 text

Where do we go from here?

Slide 72

Slide 72 text

Next steps 1. Run away from the so-called "DDD lite" 2. Start with either: - Domain-Driven Design Distilled (Vaughn Vernon) or Domain-Driven Design Quickly (Abel Avram and Floyd Marinescu) 3. Watch the talk "7 Reasons Why DDD Projects Fail" (Greg Young) 4. Make your fundamentals understanding solid, do not rush it - Domain-Driven Design aka The Blue Book (Eric Evans) or Learning Domain-Driven Design (Vlad Khononov) 5. Practice modeling and coding - Don't use AI for that, frustration is important for learning 6. Go deeper: - Learn EventStorming (Alberto Brandolini) and other techniques for domain discovery and modeling - Read Implementing Domain-Driven Design aka The Red Book (Vaughn Vernon) - Learn event-sourcing (and CQRS) - Read CQRS Documents (Greg Young) - Read Event-Driven (Oskar Dudycz) - Read Architecture for Flow (Susanne Kaiser)

Slide 73

Slide 73 text

Go ahead and practice!

Slide 74

Slide 74 text

Thank you! @talyssonoc talysson.com @codeminer42 codeminer42.com