@cyriux
Cyrille Martraire
DDDPatterns
Beyond the Blue Book
Event Storming Event Sourcing
CQRS
DDD
What	was	before?
Is	it	useful?
Can	I	get	better	at	DDD	by	looking	
at	things	outside	of	DDD?
This	talk	is	the	answer.
Passionate developer
Deliberate Designer
PARIS
Since 1999
@cyriux
Cyrille Martraire
Paris Software Craftsmanship
Community since 2011
http://www.meetup.com/paris-software-craftsmanship/
arolla.fr @arollafr
arolla.fr @arollafr
TDDBDDDDD
Software Development
Its history
Software Engineering
Tools, notations, MDA
19
Vendor-sponsored conferences
Fortunately
Eric Evans - Domain-Driven Design
Should	it	be	the	
only	book	to	read	
to	learn	Domain-
Driven	Design?
THE ONE & ONLY BOOK?
Any	headline	that	ends	
in	a	question	mark	can	
be	answered	by	no.
Eric	Evans	advocates	in	
his	book	to	look	outside	
for	more	patterns	&	
inspirations.
I	did.
For	this	talk	I	have	
selected	43	patterns	and	
I'm	going	to	explain	them	
one	by	one	now.
<Facepalm>
OK.
"The best way to get the
right answer on the Internet
is not to ask a question, it's
to post the wrong answer.”
— Cunningham’s Law
Ward Cunningham
WIKI
XP
CRC Cards
Ward Cunningham
Patterns
in software!
http://c2.com/ppr/checks.html
DDD Inspiration
CHECKS Patterns
1. Whole Value
2. Exceptional cases (absence, error…)
3. Meaningless Behavior
4. Echo Back
5. Visible Implication
6. Deferred Validation
7. Instant Projection
8. Hypothetical Publication
9. Forecast Confirmation
10. Diagnostic Query Analysis Patterns
25m	+	10m	=	35m
(Custom Arithmetics)
Whole Object with unit.
Whole Object
Whole Object
#NoPrimitive
”Because	bits,	strings	and	numbers	can	be	
used	to	represent	almost	anything,	any	one	
in	isolation	means	almost	nothing.”
Exceptional Value
NaN	
Unde:ined	
NotApplicable
25m													+	NaN											=	NaN
Don’t	clutter	your	code		
with	special	case	handing
going	further…
Cashflow Sequence
+
Cashflow Sequence
=
Cashflow Sequence
Monoid
Could we say
that?
HotelBooking
Jan26to27 HotelBooking
Jan27to29
HotelBooking
Jan26to29
+
=
Monoid
Monoids
Vector Spaces
Cyclic Groups
Monoids	
advertisement		
brought	to	you	by	
@cyriux!
CHECKS Patterns
Traceability
Normal display: 652 MM USD EQV
Diagnostic display: 622,456,325.07 USD
+ 3,624,878,450 JPY
+ 23,549.54 FRF
CHECKS Patterns
1. Whole Value
2. Exceptional cases (absence, error…)
3. Meaningless Behavior
4. Echo Back
5. Visible Implication
6. Deferred Validation
7. Instant Projection
8. Hypothetical Publication
9. Forecast Confirmation
10. Diagnostic Query Analysis Patterns
THE
WORLD’s
FIRST
WIKI
PLoP98
Mind the biblio
In most domain
models, most design
patterns are
technical noise.
observer
Singleton
Factory
Command
VISITOR
MEDIATOR
Manager
observer
PROXY
FACADE
MEMENTO
But some design
patterns also
describe business
domain concepts
and relations.
Composite
Interpreter
Flyweight
Strategy
observer
Singleton
Factory
Command
VISITOR
MEDIATOR
Manager
observer
PROXY
FACADE
MEMENTO
Good-Old hint:
”Use pattern
names in type
names.”
In a domain model,
avoid pattern names
in types names.
DateAdjustmentStrategy
Strategy
DateAdjustment
DayShiftMethod
EndOfMonthRule
RoundingConvention
CalculationMode
Strategy
DateAdjustment
DayShiftMethod
EndOfMonthRule
RoundingConvention
CalculationMode
Strategy
Belongs to the
Ubiquitous
Language
ReimbursementPolicy
EligibilityCriterion
AcceptanceSpecification
Strategy
Belongs to the
Ubiquitous Language
AccountingValuation
NetPresentValueValuation
LinearValuation
BenchmarkBasedValuation
AssetBasedValuation
Strategy
AccountingValuations
NetPresentValueValuation
LinearValuation
BenchmarkBasedValuation
AssetBasedValuation
Strategy
Belongs to the
Ubiquitous
Language
AccountingValuations
NetPresentValueValuation
LinearValuation
BenchmarkBasedValuation
AssetBasedValuation
Strategy
No Noise
ValuationImpl
Strategy
Strategy Pattern
VAT
VAT on net price
Not Applicable
Calculation
+ Null Object
Null Object.
No, you should not
replace every
Null Object with
Optional<T>
When to apply a
pattern? (or not)
IF Statements vs. Strategy pattern?
Naming-Driven
Whichever reveals the
business domain best
AccountingValuation
NetPresentValueValuation
LinearValuation
BenchmarkBasedValuation
AssetBasedValuation
Strategy
DateAdjustmentStrategy
Domain Patterns
#NotInMyName
Annotate classes with custom annotations
Stereotypes Annotations
Stereotypes Annotations
Annotate classes with custom annotations
Domain type names are
precious. They are for
domain naming.
Use annotations to
document the
stereotypes instead.
Stereotypes Annotations
Annotate classes with custom annotations
Embedded Learning
Stereotypes Annotations
Annotate with custom annotations
Stereotypes Annotations
Annotate with custom annotations
Stereotypes Annotations
Annotate domain classes with custom annotations
Stereotypes Annotations
Annotate domain classes with custom annotations
And learn on the job!
https://leanpub.com/livingdocumentation
BUY MY BOOK!
LIVING DOCUMENTATION
And	now	for	more	Object-
Oriented	Patterns
But Cyrille,
Nobody does
Object-
Oriented
anymore!
NOW WE DO
FP!
#NoPAttern
Evergreen
SKILLS
Evergreen skills
are worth
learning
So	now…	
Introducing	the	Flyweight	
pattern!
Flyweight
Intent:	Use	sharing	to	support	large	
numbers	of	[ine-grained	objects	ef[iciently
”Hahaha.
Nobody uses the
Flyweight”
A matter of
Compression
= 3x
503010 …
Flyweight
BUY SELL
503010 …
Flyweight
We always want to make
multiplicity manageable
503010 …
-503010 …
Flyweight
-503010 …
{10, 30, -50 …}
Flyweight
{10, 30, -50 …}
∑ = -10
Flyweight
∑ = -10
manageable
= aggregable,
comparable…
Flyweight
Equity Trading:
Standard Stock
Multiple Trades of the same
$10M
-
$30M
- -
$50M
x
$10M
IBM
$30M
IBM AXA
$50M
Derivative Trading:
Multiple Contracts with
a common structure
$10M
IBM
$30M
IBM AXA
$50M
Derivative Trading:
x
$10M
IBM
$30M
IBM AXA
$50M
The essence of Flyweight
x
Many small, calculable elements One Blackbox
IntrinsicExtrinsic
#WIN
Flyweight
#WIN
This never works.
I see what you mean…
BUT no way, IT DOES NOT
WORK from a legal
perspective!
FATAL
OBJECTION
FATAL
OBJECTION
as hint of bounded
Context!
Tip: Focus on one context
=
≠
≠
Works in this context only
=
≠
≠
Legal
Money
Management
It works in my context!
=
≠
Transport
Regulation
Cargo
Shipping
In what
PERSPECTIVE could
we say that?
Bounded
Context
Different Bounded
Contexts,
Different Patterns.
Different Patterns,
Different Bounded
Contexts.
#WorksInMyContext
HEY
CYRILLE
WHY U SO
FASCINATED
with patterns?
Would you build
Photoshop only
with IF statements
and FOR loops?
for (...)
if (...)
if (..)
{
for...
}
else
else
while
for (...)
if (...)
if (..)
{
for...
}
else
else
while
You should
have a look at
design patterns!
Strategy
+
State
=
EASY AGAIN!
Patterns
ABUSE
(Like every
beginner)
Then	I	discovered	Martin	Fowler
Event Sourcing-ish
Retail Banking
Medical Care
Traceability
Patterns illustrate
deeper principles.
Traceability always
points to the Past.
(aka. Consequences depend on the Cause)
ORDER
BASKET
PAYMENT
RETURN
time
refers torefers torefers to
causality
e-commerce
Study the patterns.
Digest the principles.
Apply to new domains.
CLAIM
INSURANCE
POLICY
LOSS
$
PAYMENT
time
refers torefers torefers to
causality
Insurance
Evergreen
SKILLS
Different domains,
same principle
Supple	Domain	Models
Bespoke	Code
Bespoke, Custom.
OK.
Reinventing the Wheel.
NOT OK.
https://martinfowler.com/eaaDev/timeNarrative.html
Temporal Property
https://martinfowler.com/eaaDev/timeNarrative.html
Snapshot
https://martinfowler.com/eaaDev/timeNarrative.html
Temporal Object
Effectivity Range
Agreement v1 - effectivity: [01/2016, 01/2017[
Agreement v2 - effectivity: [01/2017, 01/2018[
Agreement v3 - effectivity: [01/2018, - [
Invariant:	ranges	are	continuous	&	non-
overlapping
Effectivity Range
Agreement v1 - effectivity: [01/2016, 01/2017[
Agreement v2 - effectivity: [01/2017, 01/2018[
Agreement v3 - effectivity: [01/2018, - [
06/2017
Invariant:	ranges	are	continuous	&	non-
overlappingWhat version was
effective on this date?
https://martinfowler.com/eaaDev/timeNarrative.html
Bi-temporal Time
Time has two
dimensions in software!
[…] you may have only additive
changes. An additive change
always goes onto the end of the
record.
https://martinfowler.com/eaaDev/timeNarrative.html
Append-only
Compensation
[…] you may have only additive
changes. An additive change
always goes onto the end of the
record.
https://martinfowler.com/eaaDev/timeNarrative.html
Event-Sourcing-ish
Excellent Design
Teaching Material
Learn the
history, not just
the end state.
Learning Steps
(à la Event Sourcing)
Know the Holy Family
:)
Illustrious
Ancestors
Rebecca J. Wirfs-Brock
First RDD
paper in
1989!
http://tonyprusac.blogspot.fr/2015/11/deco2300-week-6.html
CRC Cards
Event Storming Ancestor
@mathiasverraes@ziobrando
MOAR
ANALYSIS
PATTERNS
TO DESIGN
DOMAIN
MODELS
Not just Code
Also Ideas!
Reuse all the things!
And past insights
164
A Business Transaction
A quantity of
something
(e.g. cash)
A quantity of
something
else
165
A Business Transaction
A quantity of
something
(e.g. cash)
A quantity of
something
else
Law: one side has to be cash
166
A Business Transaction
A quantity of
something
(e.g. cash)
A quantity of
something
else
Received
Date
Paid
Date
Trade
Date
Congratulations!
You can now reuse
this domain insight!
WHY NOT WRITE
YOUR OWN
PATTERNS?
SO MANY
ANALYSIS
PATTERNS
TO DESIGN
DOMAIN
MODELS
Most developers
have never seen a
domain model.
They've only seen
data models.
WHAT’S A
DOMAIN MODEL?
Let’s take an
example
Loan Approval
Loan
Application
System
Credit
Bureau
Signatures
Requests
Approval
100k$
Approved/
Rejected
Loan Approval
Loan
Application
System
Credit
Bureau
Signatures
Requests
Approval
100k$
change
to
90k$
Accept with
in-place mutation :(
Do you
approve
this 100k$
loan?
I approved
this 90k$
loan!
Do you
approve
this 100k$
loan?
… What
do I do
with that
now?!!
Answering a
different question is
rude!
(plus sync back the
mutation is not so easy)
What if we just
reject with a
suggestion to change
the amount before
re-submit?
In other words:
”Single Path to
Approval”
Jez Humble and David Farley, “Continuous Delivery: Reliable Software Releases through
Build, Test, and Deployment Automation”, Addison Wesley Professional, 2010
In other words:
”Single Path to
Approval”Production
Jez Humble and David Farley, “Continuous Delivery: Reliable Software Releases through
Build, Test, and Deployment Automation”, Addison Wesley Professional, 2010
Continuous Delivery
Loan Approval
Loan
Application
System
Credit
Bureau
Signatures
Reject + suggest
reduced amount
Requests
Approval
100k$
OK for
90k$
x
Approved/
Rejected
No patch here!
Fix the source then commit as usual
No way! It would
delay the process!
Plus we don’t want to
ask approvers to sign
again!
Business
OK.
Still, perhaps we
could do it anyway…
Dev Team
OK for 100k$
➜
a fortiori OK for 90k$
➜
”A fortiori principle”
No need to sign again!
Now we need to codify
accurately what
a fortiori means.
That’s modeling the
domain.
Not that hard:
Lower risk -> a fortiori OK.
Domain Modeling
means forming an
opinion on how it
behaves.
Programming as Theory-
Building
— Peter Naur (1985)
Anything can be an
inspiration.
Even Continuous Delivery
patterns!
Let’s take another
example
Only rebuild what needs to
be rebuilt after a change
Given a set of source code
files
http://maemo.org/maemo_release_documentation/maemo4.1.x/node5.html
http://maemo.org/maemo_release_documentation/maemo4.1.x/node5.html
http://maemo.org/maemo_release_documentation/maemo4.1.x/node5.html
Imagine doing that
with a workflow
engine?
GNU Make has an
opinion on how to
consider the
problem.
Declare the dependencies.
Let the tool find out the
workflow.
http://maemo.org/maemo_release_documentation/maemo4.1.x/node5.html
http://maemo.org/maemo_release_documentation/maemo4.1.x/node5.html
ReviewRisk
check
Legal
check
Management
Review
Management
Review
Product
Launch
R&D
Done
Sales
Ready
Marketing
Campaign
Product Specs
Product Design
A breakthrough in domain
modeling
Why insist on using
workflow engines
everywhere?
Do you have an
opinion on how to
consider the
business domain?
(Hint: ”We need Event
Sourcing” is probably not the
best answer)
Which pattern?
”Propose several models, choose one.”
Design Spike.
Try them.
Which pattern?
from simple to less simple.
Teaching Patterns
to your team mates
Mob-Programming
@woodyzuill
https://www.industriallogic.com/blog/design-patterns-playing-cards/
Design Patterns Poker cards
Design Patterns Poker cards
Show the benefits.
Don’t preach.
Own Internal Branding
You don’t have to talk
Flyweight or Monoid
The best code sample for training is
your own code base.
Embedded Learning
YOU DIDN’T SEE
ALL THESE PATTERNS
BEFORE?
You probably
procrastinate on
tech stuff.
No, you probably
don’t need this
Event Sourcing
here.
You probably should
spend more time
Domain Model
Technical Infrastructure
HERE
Design is hard?
Do it more often!
From Scratch?
Lack of domain
maturity makes
everything look
CRUD.
Mature Legacy
Systems FTW!
NEW HORIZONS
DCI by Jim Coplien #DDDEU
https://blog.acolyer.org/ http://paperswelove.org/
In closing
Many patterns authors.
Many patterns.
They converge, mostly.
No need to learn them all.
Many patterns authors.
Many patterns.
Still, learn more than one!
So many patterns outside
the Blue Book
But do you really know all
the patterns in the Blue
Book?
Merci !
h$p://cathy313.centerblog.net/539-bisounours
Follow me @cyriux
Slides: slideshare.net/cyriux
Blog: cyrille.martraire.com
We offer training, coaching & consulting on DDD, BDD, TDD

DDD patterns that were not in the book