Elevating Tactical DDD Patterns Through Object Calisthenics

DorraBARTAGUIZ 177 views 85 slides May 31, 2024
Slide 1
Slide 1 of 85
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55
Slide 56
56
Slide 57
57
Slide 58
58
Slide 59
59
Slide 60
60
Slide 61
61
Slide 62
62
Slide 63
63
Slide 64
64
Slide 65
65
Slide 66
66
Slide 67
67
Slide 68
68
Slide 69
69
Slide 70
70
Slide 71
71
Slide 72
72
Slide 73
73
Slide 74
74
Slide 75
75
Slide 76
76
Slide 77
77
Slide 78
78
Slide 79
79
Slide 80
80
Slide 81
81
Slide 82
82
Slide 83
83
Slide 84
84
Slide 85
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...


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!