SlideShare a Scribd company logo
Modelling a complex domain
with Domain-Driven Design
@NaeemSarfraz
#DDDesign #LeedsSharp
Modelling a complex domain with Domain-Driven Design
Modelling a complex domain with Domain-Driven Design
Can you tell me what is the
problem you’re trying to solve?
Modelling a complex domain with Domain-Driven Design
Is it possible to write code that
reflects the problem domain?
Could you deduce the original
requirements from your code?
Who am I?
Solutions Architect @ Barrett Steel
10+ years .NET Developer
Learn(new Things()).Like()
Play(Archery).Add(Horseriding).Like()
@NaeemSarfraz
http://naeemsarfraz.net
Silver Bullet Warning
Let’s Talk About Design…
▪ Do you do it?
▪ Big-Design-Up-Front vs Emergent Design
▪ “Working software over comprehensive documentation”
[Agile Manifesto]
▪ “Continuous attention to technical excellence and good
design enhances agility”
[Principles behind the Agile Manifesto]
▪ While we must acknowledge emergence in design and
system development, a little planning can avoid much
waste
[James Coplien, Lean Architecture]
Modelling a complex domain with Domain-Driven Design
Modelling a complex domain with Domain-Driven Design
Modelling a complex domain with Domain-Driven Design
Domain-Driven Design
What Is Domain-Driven Design?
1. Focus on the core complexity and opportunity
in the domain
2. Explore models in a collaboration of domain
experts and software experts
3. Write software that expresses those models
explicitly
4. Speak a ubiquitous language within a bounded
context
Modelling a complex domain with Domain-Driven Design
Correct Hashtag: #DDDesign
!#DDD
Modelling a complex domain with Domain-Driven Design
The Problem You’re Trying to Solve
▪ Complexity inherent in software
▪ Essential & Accidental complexity
▪ “That’s not what I meant” [An End User]
Definitions…
Problem Domain
▪ A sphere of knowledge, influence, or
activity
▪ The subject area to which the user
applies a program
Language
▪ The primary cause of misunderstanding between business &
development teams
▪ Agree and define key conceptsprocessesactors – a shared
vocabulary
▪ Avoid translations
▪ Language is reflected in code
▪ Who?
– Domain Expert (not a Product Owner)
– Development Team
Definitions…
Ubiquitous Language
▪ A language structured around the domain
model and used by all team members
within a bounded context to connect all
the activities of the team with the
software
Context
▪ Language has a meaning within a context
▪ A Model only has meaning within a context
▪ One Model to rule them all!
▪ Systems serve different user communities
▪ Define the context within which a model applies
– Library Loans
▪ Borrower of a Book
– Library Fines
▪ Member of a Library
Definitions…
Bounded Context
▪ A description of a boundary (typically a
subsystem, or the work of a particular
team) within which a particular model is
defined and applicable
Modelling
▪ Start with the key concepts in your problem domain
▪ Explore the interactions between these conceptsclasses
▪ Domain Model expressed as an Object Model
▪ Turn key concepts into pertinent classes
▪ Useful models not necessarily realistic
▪ Key: Domain-centric model not Data-centric
Modelling a complex domain with Domain-Driven Design
Modelling a complex domain with Domain-Driven Design
Modelling a complex domain with Domain-Driven Design
Modelling a complex domain with Domain-Driven Design
Modelling a complex domain with Domain-Driven Design
Modelling a complex domain with Domain-Driven Design
Definitions…
Model
▪ A system of abstractions that describes
selected aspects of a domain and can be
used to solve problems related to that
domain
Domain Model
▪ An object model of the domain that
incorporates both behaviour and data
Our Problem Domain
▪ As a Purchaser I want to be able to request to purchase goods
for independent depots So that I can purchase goods on behalf
of each specific business
▪ As a Purchaser I want to be able to request to purchase goods
that are required for multiple depots So that I can reduce the
amount of time taken to raise purchase orders required for each
depot
▪ As a Manager I want to be able to approve or reject a purchase
request So that we can follow the defined business approval
process
▪ As a Purchaser I want to be able to self-approve an order with
my self-approval limit So that I can purchase items which
require no approval
What are the Key Concepts?
Modelling a complex domain with Domain-Driven Design
Modelling a complex domain with Domain-Driven Design
Modelling a complex domain with Domain-Driven Design
Modelling a complex domain with Domain-Driven Design
The core domain is the part of
the domain most closely
associated with the strategy of
the company
Core Domain
Purpose Alignment Model
MarketDifferentiation
Mission Critical
Does anyone care?
Invest
Parity
Partner
Partner – Do we need
to take this on? Find
a partner
Parity – Achieve and
maintain parity
Invest – Excel and
innovate here, support
USP
Core Domain
Supporting
Sub-Domain
Generic
Sub-Domain
Modelling a complex domain with Domain-Driven Design
Modelling a complex domain with Domain-Driven Design
Entities
▪ An individual “thing”
▪ Has an identity
▪ Has a life
▪ Mutable
▪ Equality comparison using identity
Value Objects
▪ “Primitive Obsession”
▪ Doesn’t have an identity
▪ Equality comparison using properties
▪ Immutable
A Word About Immutability
▪ More Immutable structures = betterreliable code
▪ Type safety
▪ Side-effect free
▪ Try to move behavioural responsibilities into Value Objects
▪ Keep management of state in the Entity
Modelling a complex domain with Domain-Driven Design
Modelling a complex domain with Domain-Driven Design
Modelling a complex domain with Domain-Driven Design
Definitions…
Entities
▪ Objects that have a distinct identity
that runs through time and different
representations
Value Objects
▪ A small simple object, like money or a
date range, whose equality isn't based on
identity
Beware of Anti-Patterns
▪ Anaemic Domain Model
▪ The Leaky Model
▪ Partially Initialised Entities
Domain Services
▪ Sometimes, it just isn’t a thing
▪ First class citizens so name is part of Ubiquitous Language
▪ Exposed as a service
▪ A stateless operation
▪ Examples:
– LoanAnItem
– PlaceReservation
▪ Not an Application Service
– IEmailSender
– These depend on Infrastructure
Domain Events
▪ Something happened that the domain expert cares about
▪ First class citizens so name is part of Ubiquitous Language
▪ Named in the past tense e.g. ItemWasLoanedEvent
▪ Immutable – a record of something in the past
Modelling a complex domain with Domain-Driven Design
Definitions…
Domain Service
▪ A processtransformation in the domain
that is not a natural responsibility of an
entity or a value object
Domain Events
▪ A full-fledged part of the domain model, a
representation of something that happened
in the domain
Aggregates
▪ Collection of Entities and Value Objects treated as a conceptual
whole
▪ Root Entity is the Aggregate’s conceptual name
▪ Business defines the invariants
▪ External references are restricted to the root only
▪ Smaller the better
▪ Consistency:
– Logically consistent within an Aggregate via transaction
– Eventually consistent across Aggregates via propagating updates async
▪ Repository used to load and save an Aggregate
Definitions…
Aggregate
▪ A cluster of associated objects that are
treated as a unit for the purpose of
data changes
Presentation Layer
Business Layer
Data Access Layer
Data Storage Layer
Modelling a complex domain with Domain-Driven Design
Modelling a complex domain with Domain-Driven Design
Loans Context
Fines Context
Loan
Aggregate
Account
Aggregate
Book
Returned
Modelling a complex domain with Domain-Driven Design
Visual Studio time…
Model Exploration Whirlpool
▪ Start with a reference scenario
▪ Propose a model
▪ Code probe
▪ Repeat
Modelling a complex domain with Domain-Driven Design
Event Storming
▪ Take one big room with lots of clear surfaces
▪ Add Domain Experts and Developers
▪ Give them lots of sticky notes & sharpies (trust me you’ll
need lots)
▪ And get them to…talk?
Time
Book
Reserved
Book
Returned
Member
Pays
Money
Book
Loaned Fine Paid
Lorem
Ipsum
Dolored
Lorem
Ipsum
Dolored
Lorem
Ipsum
Dolored
Lorem
Ipsum
Dolored
Lorem
Ipsum
Dolored
Can we
pay
later?
Lorem
Ipsum
Dolored
What’s if
the book
is never
available
Places
Reservation
Can we
pay half
the fine?
In Summary
Modelling a complex domain with Domain-Driven Design
Modelling a complex domain with Domain-Driven Design
Modelling a complex domain with Domain-Driven Design
Modelling a complex domain with Domain-Driven Design
Modelling a complex domain with Domain-Driven Design
In Summary
▪ Knowing when to use it
▪ Domain centric modelling not data centric
▪ Work with your Domain Experts
▪ Give OO Design another chance
▪ Use Value Objects
▪ Do some f@*?ing design
Thank You
Any Questions?
t: @NaeemSarfraz
e: Naeem.Sarfraz@gmail.com
Follow up…
Events
▪ DDD Europe 2017 - Amsterdam
– https://dddeurope.com/2017
▪ DDDx 2017 – London
– https://skillsmatter.com
Pluralsight
▪ Domain-Driven Design in
Practise
▪ Domain-Driven Design
Fundamentals

More Related Content

What's hot (20)

PPTX
Domain Driven Design
Araf Karsh Hamid
 
PDF
Domain Driven Design
Harsh Jegadeesan
 
PPTX
Domain-Driven Design
Andriy Buday
 
PPTX
Introduction to DDD
Eduards Sizovs
 
PPTX
How to Implement Domain Driven Design in Real Life SDLC
Abdul Karim
 
PPTX
Domain Driven Design: Zero to Hero
Fabrício Rissetto
 
PPT
Domain Driven Design (DDD)
Tom Kocjan
 
PPTX
Domain Driven Design
Ryan Riley
 
PPTX
Domain Driven Design Quickly
Mariam Hakobyan
 
PDF
Refactoring for Domain Driven Design
David Berliner
 
PPTX
Brownfield Domain Driven Design
Nicolò Pignatelli
 
PPTX
Domain driven design
Mustafa Dağdelen
 
PDF
Clean Architecture
NSCoder Mexico
 
PPTX
A Practical Guide to Domain Driven Design: Presentation Slides
thinkddd
 
PDF
Domain Driven Design
Nikolay Vasilev
 
PDF
Domain Driven Design
AOE
 
PPTX
Domain driven design
Amit Mukherjee
 
PDF
Deconstructing Monoliths with Domain Driven Design
VMware Tanzu
 
PDF
Introducing Clean Architecture
Roc Boronat
 
PPTX
Clean Architecture
Zahra Heydari
 
Domain Driven Design
Araf Karsh Hamid
 
Domain Driven Design
Harsh Jegadeesan
 
Domain-Driven Design
Andriy Buday
 
Introduction to DDD
Eduards Sizovs
 
How to Implement Domain Driven Design in Real Life SDLC
Abdul Karim
 
Domain Driven Design: Zero to Hero
Fabrício Rissetto
 
Domain Driven Design (DDD)
Tom Kocjan
 
Domain Driven Design
Ryan Riley
 
Domain Driven Design Quickly
Mariam Hakobyan
 
Refactoring for Domain Driven Design
David Berliner
 
Brownfield Domain Driven Design
Nicolò Pignatelli
 
Domain driven design
Mustafa Dağdelen
 
Clean Architecture
NSCoder Mexico
 
A Practical Guide to Domain Driven Design: Presentation Slides
thinkddd
 
Domain Driven Design
Nikolay Vasilev
 
Domain Driven Design
AOE
 
Domain driven design
Amit Mukherjee
 
Deconstructing Monoliths with Domain Driven Design
VMware Tanzu
 
Introducing Clean Architecture
Roc Boronat
 
Clean Architecture
Zahra Heydari
 

Viewers also liked (20)

PPTX
Designing APIs and Microservices Using Domain-Driven Design
LaunchAny
 
PDF
Domain Driven Design Introduction
Tung Nguyen Thanh
 
PPT
Designing For Your Least Able User
fantasticlife
 
PDF
Mike Atherton - Domain modelling at the BBC
lightningUX
 
PDF
Domain Modelling
kim.mens
 
PPT
How We Make Websites
fantasticlife
 
PDF
Building Event Driven Systems
WSO2
 
PDF
Domain-Driven Design at ZendCon 2012
Bradley Holt
 
PPTX
Domain-Driven Design: The "What" and the "Why"
bincangteknologi
 
PPTX
Domain-Driven Design workshops
Mariusz Kopylec
 
PDF
Domain-Driven Design und Hexagonale Architektur
Torben Fojuth
 
PPTX
Domain driven design
jstack
 
KEY
An Introduction to Domain Driven Design for Product Managers
r4isstatic
 
PDF
What is DDD and how could it help you
Luis Henrique Mulinari
 
PDF
Agile development and domain driven design
Jacopo Romei
 
KEY
ZendCon 2011 UnCon Domain-Driven Design
Bradley Holt
 
PDF
Domain-driven design - tactical patterns
Tom Janssens
 
PDF
From legacy to DDD
Andrzej Krzywda
 
PDF
Introduction to Domain Driven Design
Christos Tsakostas
 
PDF
Ddd reboot (english version)
Thomas Pierrain
 
Designing APIs and Microservices Using Domain-Driven Design
LaunchAny
 
Domain Driven Design Introduction
Tung Nguyen Thanh
 
Designing For Your Least Able User
fantasticlife
 
Mike Atherton - Domain modelling at the BBC
lightningUX
 
Domain Modelling
kim.mens
 
How We Make Websites
fantasticlife
 
Building Event Driven Systems
WSO2
 
Domain-Driven Design at ZendCon 2012
Bradley Holt
 
Domain-Driven Design: The "What" and the "Why"
bincangteknologi
 
Domain-Driven Design workshops
Mariusz Kopylec
 
Domain-Driven Design und Hexagonale Architektur
Torben Fojuth
 
Domain driven design
jstack
 
An Introduction to Domain Driven Design for Product Managers
r4isstatic
 
What is DDD and how could it help you
Luis Henrique Mulinari
 
Agile development and domain driven design
Jacopo Romei
 
ZendCon 2011 UnCon Domain-Driven Design
Bradley Holt
 
Domain-driven design - tactical patterns
Tom Janssens
 
From legacy to DDD
Andrzej Krzywda
 
Introduction to Domain Driven Design
Christos Tsakostas
 
Ddd reboot (english version)
Thomas Pierrain
 
Ad

Similar to Modelling a complex domain with Domain-Driven Design (20)

PDF
Code & Cannoli - Domain Driven Design
Frank Levering
 
PDF
Domain driven design: a gentle introduction
Asher Sterkin
 
PPTX
Schibsted Spain - Day 1 - DDD Course
Kevin Mas Ruiz
 
PDF
RSG Sri Lanka Presentation - Ravindra Perera- Public Version.pdf
Ravindra Perera CC MBA(PIM), 6 Sigma (Green Belt)
 
ODP
Into the domain
Knoldus Inc.
 
PDF
Domain Driven Design @ NewStore
Bernardo Torres
 
PDF
D2 domain driven-design
Arnaud Bouchez
 
PDF
Structured Authoring for Business-Critical Content
LavaCon
 
PPTX
Seminar - Scalable Enterprise Application Development Using DDD and CQRS
Mizanur Sarker
 
PDF
L05 Design Patterns
Ólafur Andri Ragnarsson
 
PPTX
"How do I Architect?" - Quick Introduction to Architecture for Salesforce Ad...
Steven Herod
 
PDF
Behavior Driven Development
NETUserGroupBern
 
PPTX
Domain Driven Design
Lalit Kale
 
PPTX
An Introduction to Domain Driven Design in PHP
Chris Renner
 
PPTX
Designing DDD Aggregates
Andrew McCaughan
 
PPTX
Cloud Enablement Engine Role Definition and Mapping
Tom Laszewski
 
PDF
How I ended up contributing to Magento core
Alessandro Ronchi
 
PDF
Extreme DDD Modelling Patterns - 2024 Devoxx Poland
Alberto Brandolini
 
PDF
Beyond rails new
Paul Oguda
 
PDF
Domain Driven Design
Mojammel Haque
 
Code & Cannoli - Domain Driven Design
Frank Levering
 
Domain driven design: a gentle introduction
Asher Sterkin
 
Schibsted Spain - Day 1 - DDD Course
Kevin Mas Ruiz
 
RSG Sri Lanka Presentation - Ravindra Perera- Public Version.pdf
Ravindra Perera CC MBA(PIM), 6 Sigma (Green Belt)
 
Into the domain
Knoldus Inc.
 
Domain Driven Design @ NewStore
Bernardo Torres
 
D2 domain driven-design
Arnaud Bouchez
 
Structured Authoring for Business-Critical Content
LavaCon
 
Seminar - Scalable Enterprise Application Development Using DDD and CQRS
Mizanur Sarker
 
L05 Design Patterns
Ólafur Andri Ragnarsson
 
"How do I Architect?" - Quick Introduction to Architecture for Salesforce Ad...
Steven Herod
 
Behavior Driven Development
NETUserGroupBern
 
Domain Driven Design
Lalit Kale
 
An Introduction to Domain Driven Design in PHP
Chris Renner
 
Designing DDD Aggregates
Andrew McCaughan
 
Cloud Enablement Engine Role Definition and Mapping
Tom Laszewski
 
How I ended up contributing to Magento core
Alessandro Ronchi
 
Extreme DDD Modelling Patterns - 2024 Devoxx Poland
Alberto Brandolini
 
Beyond rails new
Paul Oguda
 
Domain Driven Design
Mojammel Haque
 
Ad

Recently uploaded (20)

PPTX
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
PPTX
The Role of a PHP Development Company in Modern Web Development
SEO Company for School in Delhi NCR
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PDF
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PPTX
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
PDF
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
PDF
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
PDF
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
PPTX
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
PPT
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
PPTX
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
PPTX
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
PPTX
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
PPTX
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
The Role of a PHP Development Company in Modern Web Development
SEO Company for School in Delhi NCR
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
Human Resources Information System (HRIS)
Amity University, Patna
 
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 

Modelling a complex domain with Domain-Driven Design

  • 1. Modelling a complex domain with Domain-Driven Design @NaeemSarfraz #DDDesign #LeedsSharp
  • 4. Can you tell me what is the problem you’re trying to solve?
  • 6. Is it possible to write code that reflects the problem domain?
  • 7. Could you deduce the original requirements from your code?
  • 8. Who am I? Solutions Architect @ Barrett Steel 10+ years .NET Developer Learn(new Things()).Like() Play(Archery).Add(Horseriding).Like() @NaeemSarfraz http://naeemsarfraz.net
  • 10. Let’s Talk About Design… ▪ Do you do it? ▪ Big-Design-Up-Front vs Emergent Design ▪ “Working software over comprehensive documentation” [Agile Manifesto] ▪ “Continuous attention to technical excellence and good design enhances agility” [Principles behind the Agile Manifesto] ▪ While we must acknowledge emergence in design and system development, a little planning can avoid much waste [James Coplien, Lean Architecture]
  • 15. What Is Domain-Driven Design? 1. Focus on the core complexity and opportunity in the domain 2. Explore models in a collaboration of domain experts and software experts 3. Write software that expresses those models explicitly 4. Speak a ubiquitous language within a bounded context
  • 19. The Problem You’re Trying to Solve ▪ Complexity inherent in software ▪ Essential & Accidental complexity ▪ “That’s not what I meant” [An End User]
  • 20. Definitions… Problem Domain ▪ A sphere of knowledge, influence, or activity ▪ The subject area to which the user applies a program
  • 21. Language ▪ The primary cause of misunderstanding between business & development teams ▪ Agree and define key conceptsprocessesactors – a shared vocabulary ▪ Avoid translations ▪ Language is reflected in code ▪ Who? – Domain Expert (not a Product Owner) – Development Team
  • 22. Definitions… Ubiquitous Language ▪ A language structured around the domain model and used by all team members within a bounded context to connect all the activities of the team with the software
  • 23. Context ▪ Language has a meaning within a context ▪ A Model only has meaning within a context ▪ One Model to rule them all! ▪ Systems serve different user communities ▪ Define the context within which a model applies – Library Loans ▪ Borrower of a Book – Library Fines ▪ Member of a Library
  • 24. Definitions… Bounded Context ▪ A description of a boundary (typically a subsystem, or the work of a particular team) within which a particular model is defined and applicable
  • 25. Modelling ▪ Start with the key concepts in your problem domain ▪ Explore the interactions between these conceptsclasses ▪ Domain Model expressed as an Object Model ▪ Turn key concepts into pertinent classes ▪ Useful models not necessarily realistic ▪ Key: Domain-centric model not Data-centric
  • 32. Definitions… Model ▪ A system of abstractions that describes selected aspects of a domain and can be used to solve problems related to that domain Domain Model ▪ An object model of the domain that incorporates both behaviour and data
  • 33. Our Problem Domain ▪ As a Purchaser I want to be able to request to purchase goods for independent depots So that I can purchase goods on behalf of each specific business ▪ As a Purchaser I want to be able to request to purchase goods that are required for multiple depots So that I can reduce the amount of time taken to raise purchase orders required for each depot ▪ As a Manager I want to be able to approve or reject a purchase request So that we can follow the defined business approval process ▪ As a Purchaser I want to be able to self-approve an order with my self-approval limit So that I can purchase items which require no approval
  • 34. What are the Key Concepts?
  • 39. The core domain is the part of the domain most closely associated with the strategy of the company Core Domain
  • 40. Purpose Alignment Model MarketDifferentiation Mission Critical Does anyone care? Invest Parity Partner Partner – Do we need to take this on? Find a partner Parity – Achieve and maintain parity Invest – Excel and innovate here, support USP Core Domain Supporting Sub-Domain Generic Sub-Domain
  • 43. Entities ▪ An individual “thing” ▪ Has an identity ▪ Has a life ▪ Mutable ▪ Equality comparison using identity
  • 44. Value Objects ▪ “Primitive Obsession” ▪ Doesn’t have an identity ▪ Equality comparison using properties ▪ Immutable
  • 45. A Word About Immutability ▪ More Immutable structures = betterreliable code ▪ Type safety ▪ Side-effect free ▪ Try to move behavioural responsibilities into Value Objects ▪ Keep management of state in the Entity
  • 49. Definitions… Entities ▪ Objects that have a distinct identity that runs through time and different representations Value Objects ▪ A small simple object, like money or a date range, whose equality isn't based on identity
  • 50. Beware of Anti-Patterns ▪ Anaemic Domain Model ▪ The Leaky Model ▪ Partially Initialised Entities
  • 51. Domain Services ▪ Sometimes, it just isn’t a thing ▪ First class citizens so name is part of Ubiquitous Language ▪ Exposed as a service ▪ A stateless operation ▪ Examples: – LoanAnItem – PlaceReservation ▪ Not an Application Service – IEmailSender – These depend on Infrastructure
  • 52. Domain Events ▪ Something happened that the domain expert cares about ▪ First class citizens so name is part of Ubiquitous Language ▪ Named in the past tense e.g. ItemWasLoanedEvent ▪ Immutable – a record of something in the past
  • 54. Definitions… Domain Service ▪ A processtransformation in the domain that is not a natural responsibility of an entity or a value object Domain Events ▪ A full-fledged part of the domain model, a representation of something that happened in the domain
  • 55. Aggregates ▪ Collection of Entities and Value Objects treated as a conceptual whole ▪ Root Entity is the Aggregate’s conceptual name ▪ Business defines the invariants ▪ External references are restricted to the root only ▪ Smaller the better ▪ Consistency: – Logically consistent within an Aggregate via transaction – Eventually consistent across Aggregates via propagating updates async ▪ Repository used to load and save an Aggregate
  • 56. Definitions… Aggregate ▪ A cluster of associated objects that are treated as a unit for the purpose of data changes
  • 57. Presentation Layer Business Layer Data Access Layer Data Storage Layer
  • 63. Model Exploration Whirlpool ▪ Start with a reference scenario ▪ Propose a model ▪ Code probe ▪ Repeat
  • 65. Event Storming ▪ Take one big room with lots of clear surfaces ▪ Add Domain Experts and Developers ▪ Give them lots of sticky notes & sharpies (trust me you’ll need lots) ▪ And get them to…talk?
  • 66. Time Book Reserved Book Returned Member Pays Money Book Loaned Fine Paid Lorem Ipsum Dolored Lorem Ipsum Dolored Lorem Ipsum Dolored Lorem Ipsum Dolored Lorem Ipsum Dolored Can we pay later? Lorem Ipsum Dolored What’s if the book is never available Places Reservation Can we pay half the fine?
  • 73. In Summary ▪ Knowing when to use it ▪ Domain centric modelling not data centric ▪ Work with your Domain Experts ▪ Give OO Design another chance ▪ Use Value Objects ▪ Do some f@*?ing design
  • 75. Follow up… Events ▪ DDD Europe 2017 - Amsterdam – https://dddeurope.com/2017 ▪ DDDx 2017 – London – https://skillsmatter.com Pluralsight ▪ Domain-Driven Design in Practise ▪ Domain-Driven Design Fundamentals