Elevating Tactical DDD Patterns Through Object Calisthenics
DorraBARTAGUIZ
177 views
85 slides
May 31, 2024
Slide 1 of 85
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
About This Presentation
After immersing yourself in the blue book and its red counterpart, attending DDD-focused conferences, and applying tactical patterns, you're left with a crucial question: How do I ensure my design is effective? Tactical patterns within Domain-Driven Design (DDD) serve as guiding principles for c...
After immersing yourself in the blue book and its red counterpart, attending DDD-focused conferences, and applying tactical patterns, you're left with a crucial question: How do I ensure my design is effective? Tactical patterns within Domain-Driven Design (DDD) serve as guiding principles for creating clear and manageable domain models. However, achieving success with these patterns requires additional guidance. Interestingly, we've observed that a set of constraints initially designed for training purposes remarkably aligns with effective pattern implementation, offering a more ‘mechanical’ approach. Let's explore together how Object Calisthenics can elevate the design of your tactical DDD patterns, offering concrete help for those venturing into DDD for the first time!
Size: 20.77 MB
Language: en
Added: May 31, 2024
Slides: 85 pages
Slide Content
Dorra Bartaguiz
•VP Tech
•Co-author & illustrator
•Different Roles
•DEV/Architect
•Coach/trainer
•Teacher
•Consulting company
•Training centre
•TDD, BDD, DDD
•Pragmatic Architecture
•Pragmatic API Design
Entity
Service
Repository
Value Object
Aggregate
DDD tactical patterns
How can we ensure
DDD tactical patterns
are well implemented
A set of constraints
aligns with effective
pattern implementation
Object calisthenics
Calisthenics – Street Workout
•Greek : Kallos sthenos
•Beauty and courage•The art of training and bodybuilding
with bodyweight and without
equipment
Object Calisthenics – Jeff Bay
? Only One Level Of Indentation Per Method
? Don’t Use The ELSE Keyword
? Wrap All Primitives And Strings
? First Class Collections
? One Dot Per Line
? Don’t Abbreviate
? Keep All Entities Small
? No Classes With More Than Two Instance Variables
? No Getters/Setters/Properties
After several years of
experience and experimentation
Object Calisthenics serving DDD
? Wrap All Primitives And Strings
? First Class Collections
? Don’t Abbreviate
? No Getters/Setters/Properties
? One Dot Per Line
? Don’t Use The ELSE Keyword
? Only One Level Of Indentation Per Method
? Keep All Entities Small
? No Classes With More Than Two Instance Variables
Wrap all primitives
and strings
•Drawbacks of Primitive obsession
•Lake of clarity
•Error-proneness
•Code duplication
•Reduced flexibility
Why?
Identify business
concepts &
domain language
Refactor
Wrap all primitives
and strings
Identity and secure
domain concepts
Object Calisthenics serving DDD
? Wrap All Primitives And Strings
? First Class Collections
? Don’t Abbreviate
? No Getters/Setters/Properties
? One Dot Per Line
? Don’t Use The ELSE Keyword
? Only One Level Of Indentation Per Method
? Keep All Entities Small
? No Classes With More Than Two Instance Variables
First class
collections
Cow
Cattle
House
&
Neighbourhood
Ship
&
Fleet
Do we have a
distinct noun for
plural forms
First class collections
First class collections
Same type!
First class collections
Can be static!
First class collections
First class
collections
Enriched business
language
Rich model
Object Calisthenics serving DDD
? Wrap All Primitives And Strings
? First Class Collections
? Don’t Abbreviate
? No Getters/Setters/Properties
? One Dot Per Line
? Don’t Use The ELSE Keyword
? Only One Level Of Indentation Per Method
? Keep All Entities Small
? No Classes With More Than Two Instance Variables
Don’t
abbreviate!
Estimated Time of Arrival
Emergency Transportation Assistance
Medical Emergencies
Educational Technology Assessment
Teacher training
Don’t abbreviate
Don’t
abbreviate!
Explicit domain
concepts
Object Calisthenics serving DDD
? Wrap All Primitives And Strings
? First Class Collections
? Don’t Abbreviate
? No Getters/Setters/Properties
? One Dot Per Line
? Don’t Use The ELSE Keyword
? Only One Level Of Indentation Per Method
? Keep All Entities Small
? No Classes With More Than Two Instance Variables
No
getters/setters/
properties
•Drawbacks of separating data and behaviour
•Anaemic domain model
•Lack of immutability
•Higher coupling
•“Tell don’t ask” principle!
Move the behaviour into domain concepts
Secure your
domain concepts
Domain Language in code
No
getters/setters/
properties
Transpose the domain
language into your code
Secure your
domain concepts
Object Calisthenics serving DDD
? Wrap All Primitives And Strings
? First Class Collections
? Don’t Abbreviate
? No Getters/Setters/Properties
? One Dot Per Line
? Don’t Use The ELSE Keyword
? Only One Level Of Indentation Per Method
? Keep All Entities Small
? No Classes With More Than Two Instance Variables
•Law of Demeter
•Don’t talk to strangers, only talk to your immediate friends
•Tell, don’t ask
Tom Thumb
“Le petit poucet” in French
Use a fluent interface
Object Calisthenics serving DDD
? Wrap All Primitives And Strings
? First Class Collections
? Don’t Abbreviate
? No Getters/Setters/Properties
? One Dot Per Line
? Don’t Use The ELSE Keyword
? Only One Level Of Indentation Per Method
? Keep All Entities Small
? No Classes With More Than Two Instance Variables
Don’t Use The ELSE Keyword
•Hard to read
•“Arrow” antipattern
•Linear code, easy to read
•“The faster you can fail, the faster you can succeed”
Don’t Use The ELSE Keyword
Design differently
•Strategy pattern
•Null object pattern
Object Calisthenics serving DDD
? Wrap All Primitives And Strings
? First Class Collections
? Don’t Abbreviate
? No Getters/Setters/Properties
? One Dot Per Line
? Don’t Use The ELSE Keyword
? Only One Level Of Indentation Per Method
? Keep All Entities Small
? No Classes With More Than Two Instance Variables
Only One Level Of
Indentation Per Method
Only One Level Of Indentation Per Method
+1
indentation
=
+1
cyclomatic complexity
(minimum)
Only One Level Of Indentation Per Method
Only One Level Of
Indentation Per Method
•Explicit
intention
•Enrich model
•Use domain
language
Object Calisthenics serving DDD
? Wrap All Primitives And Strings
? First Class Collections
? Don’t Abbreviate
? No Getters/Setters/Properties
? One Dot Per Line
? Don’t Use The ELSE Keyword
? Only One Level Of Indentation Per Method
? Keep All Entities Small
? No Classes With More Than Two Instance Variables
Keep All
Entities Small
Keep all entities small
Make big things from small things
in the same way. That’s the power
of composition.
Scott Wlaschin
Keep all entities
small, even
aggregates!
Cyrille’s Story
Family as an
aggregate
Keep all entities small
Don’t trust every use case.
Vaughn Vernon
An adult
alone?
Invariant
=
No child alone
Find invariants
correctly
Keep All
Entities Small,
even
aggregates
Object Calisthenics serving DDD
? Wrap All Primitives And Strings
? First Class Collections
? Don’t Abbreviate
? No Getters/Setters/Properties
? One Dot Per Line
? Don’t Use The ELSE Keyword
? Only One Level Of Indentation Per Method
? Keep All Entities Small
? No Classes With More Than Two Instance Variables
No Classes With More Than
Two Instance Variables
Period has a value ?
What is that value ?
No Classes With More Than
Two Instance Variables
Period has a value ?
What is that value ?
No Classes With More Than
Two Instance Variables
3. Wrap All Primitives And Strings
Period has a value ?
What is that value ?
No Classes With More Than
Two Instance Variables
Payoff
amount
date
description
currency
label
Amount
amount
currency
Reason
description
label
Payoff
amount
date
reason
No Classes With More Than
Two Instance Variables
Allocation
Reservation
Performance
play
startDate
endDate
performanceNature
Topology
No Classes With More Than
Two Instance Variables
Performance nature: standard, pre-premiere
Allocation
TheaterSession
title
startDate
Reservation
PerformanceNature
value
Performance
play
date: {startDate, endDate}
nature
Topology
No Classes With More Than
Two Instance Variables
No Classes With More Than Two
Instance Variables
Discover and
learn more about
your domain
language to a
better design
Object Calisthenics serving DDD
? Wrap All Primitives And Strings
? First Class Collections
? Don’t Abbreviate
? No Getters/Setters/Properties
? One Dot Per Line
? Don’t Use The ELSE Keyword
? Only One Level Of Indentation Per Method
? Keep All Entities Small
? No Classes With More Than Two Instance Variables
Object Calisthenics serving DDD
? Wrap All Primitives And Strings
? First Class Collections
? Don’t Abbreviate
? No Getters/Setters/Properties
? One Dot Per Line
? Don’t Use The ELSE Keyword
? Only One Level Of Indentation Per Method
? Keep All Entities Small
? No Classes With More Than Two Instance Variables Domain language
Domain language
Domain language
Domain language
Domain language
Domain language
Domain language
Domain language
Domain language
That’s the
DDD
obsession!
9 simple, stupid rules
that work
Find the xmind file here
Object Calisthenics
=
Better
implementation of
DDD tactical
patterns
Enjoy your
Calisthenics
journey!
@DorraBartaguiz
Thank you!
French reader,
buy the book!