how_does_ddd_work

33
How does Domain-Driven Design work? Tomaš Maconko [email protected]

Transcript of how_does_ddd_work

Page 1: how_does_ddd_work

How does Domain-Driven Design work?

Tomaš [email protected]

Page 2: how_does_ddd_work

What is it?“That’s just a rubbish theory!”“Its just another way to structure your code!”“Its hard to understand!”“It requires lots of useless coding!”“Nobody wants to use it!”

Page 3: how_does_ddd_work
Page 4: how_does_ddd_work

What is it?“Domain-driven design (DDD) is an approach to software development for complex needs by connecting the implementation to an evolving model.”

Page 5: how_does_ddd_work

What is complexity?•Business is the domain•Complexity is the domain (problem) itself•Domain consists of complex processes, workflows, rules etc. •Different specialists collaborate together to make business value

Page 6: how_does_ddd_work

CAR BUSINESS DOMAIN

Page 7: how_does_ddd_work

Domain areas

Core subdomain

Supporting subdomains

Page 8: how_does_ddd_work

Core subdomain and supporting subdomains•DDD requires you to examine the business deeply• It enables you to split up the problem into smaller pieces (subdomains) to outline the core piece (core subdomain)•Allows you to pay attention to each piece separately (even to work in different teams) and concentrate mostly on the core

Page 9: how_does_ddd_work

Core subdomain

Page 10: how_does_ddd_work

Lets look inside• Marketing• Sales• Billing• Production• Logistics• Operations• …

Page 11: how_does_ddd_work

BOUNDED CONTEXTS

Page 12: how_does_ddd_work

Bounded context•A pattern in Domain-Driven Design•A chunk of solution space•Helps dealing with large models•Ubiquitous language

Page 13: how_does_ddd_work

Ubiquitous language

Page 14: how_does_ddd_work

Ubiquitous language•Requires people in same bounded context using same terms (dictionary)•Same term is unambiguous for all team members (domain experts, developers, QA, etc.)•Defined and maintainable by whole team

Page 15: how_does_ddd_work

Car (production): engine, wheels,

body, …

Car (billing): car parts expenses,

salaries

Car (marketing): photo, video, description, …

Tomas Maconko
Page 16: how_does_ddd_work

PRODUCTION

Page 17: how_does_ddd_work

Value object•Does not have identity•Comparable by all its attributes•IMMUTABLE!•Allows to encapsulate business rules

Page 18: how_does_ddd_work

Value object

Page 19: how_does_ddd_work

Entity•A set of attributes and verbs•Has identity (engine ID number)•Cannot (logically) work without aggregate•Mutable

Page 20: how_does_ddd_work

Entity

Page 21: how_does_ddd_work

Aggregate and aggregate root•Entity• Joins related entities and value objects•Encapsulates complex and state-dependent requirements in domain classes• It is highly recommended (required) to have single aggregate per transaction

Page 22: how_does_ddd_work

Aggregate

Page 23: how_does_ddd_work

Aggregate root

Page 24: how_does_ddd_work

Respository• Encapsulates aggregates persistence and retrieval• Persistence ignorance• Can be used as abstraction for different underlying

technologies (SQL, NoSQL, web-services, caching, etc.)• One repository per aggregate

Page 25: how_does_ddd_work

Repository

Page 26: how_does_ddd_work

INTEGRATION

Tomas Maconko
Page 27: how_does_ddd_work

How to combine stuff together?2. Stop pedal

pressed!

1. I listen for stop pedal

pressed

1. I listen for stop pedal

pressed3. I handle it

3. I handle it

4. Started

stopping

4. Stop lights turned

on

1. I listen for

acceleration pedal

pressed

Page 28: how_does_ddd_work

Domain event•Messages in past tense•Result of completed command• Integrates aggregates or bounded contexts with minimal coupling and dependencies•Reduces the number of changes in existing code• Improves responsiveness (asynchronous processing)

Page 29: how_does_ddd_work

THAT’S IT!

Page 30: how_does_ddd_work

Pros• Involves team into domain analysis•Helps splitting and understanding the domain•Unambiguous terms• Changes the way developers think about solution• Strong domain model• Clean and maintainable code

DDD

Domain

Page 31: how_does_ddd_work

Cons•Requires team time and effort for analysis•Requires stronger skills on modeler side and OOP•Complicates small systems•Requires time to define UL DDD

Page 32: how_does_ddd_work

So, what next?• CQRS• Event sourcing• Microservices

Page 33: how_does_ddd_work