Slide 1

Slide 1 text

Starring With Directed by In the role of Also Starring

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

@hschwentner Domain-Driven Design

Slide 5

Slide 5 text

@hschwentner #dddesign

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

»Business-Software die Spaß macht«

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

@hschwentner Timetable

Slide 15

Slide 15 text

Workshop Workshop Workshop Workshop Morning Afternoon Not remote

Slide 16

Slide 16 text

Morning Afternoon Wor ksho p Wor ksho p Wor ksho p Wor ksho p Wor ksho p Wor ksho p Wor ksho p

Slide 17

Slide 17 text

@hschwentner Contents

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

@hschwentner #unabsteigbar

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

Workshop Domain-Driven Design concrete wps.de/ddd

Slide 25

Slide 25 text

Ubiquitous Language

Slide 26

Slide 26 text

Ubiquitous Language Building Blocks Domain Event Aggregate Entity Value Object Bounded Context Strategic Design Context Mapping Collaborative Modeling Domain Expert Event Storming Modeling in Code Domain Storytelling Core Domain Domain Model

Slide 27

Slide 27 text

Microservices CQRS Hexagonal Architecture Agile Event Sourcing Extreme Programming Scrum Cloud Self-Contained Systems Verticals Clean Architecture DevOps AWS Azure Onion Architecture

Slide 28

Slide 28 text

@hschwentner Structure

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

26.09.23 //// Seite 71 WPS – Workplace Solutions DOMÄNE DOMÄNE

Slide 31

Slide 31 text

@hschwentner You

Slide 32

Slide 32 text

Programming Languages My Questions My life as a developer My experiences using DDD My wishes regarding the training family My first computer

Slide 33

Slide 33 text

Story Time

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

Grafik: Robert Gloth/Wikipedia

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

Foto: Serge Melki/Wikipedia

Slide 39

Slide 39 text

Foto: Public Domain/Wikipedia

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

@hschwentner How is that supposed to work?

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

Foto: Henning Schwentner

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

Detail: Depth

Slide 47

Slide 47 text

Detail: Tiefenzahl

Slide 48

Slide 48 text

Foto: Afrank99/Wikipedia

Slide 49

Slide 49 text

Foto: Henning Schwentner

Slide 50

Slide 50 text

No content

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

PUTS NAVIGATING OFFICER CAPTAIN ASKS FOR 7 SHIP SILHOUETTE ON CARTO- GRAPHER SOUNDING SHIP DEPTH MEASURES 1 SENDS 2 TO CALCULATES 3 DRAW S 4 SENDS 5 DEPTH MAP TO MOVES & TURNS 8 SHIP SILHOUETTE TO FIND 9 DISCUSSES WITH 6 ROUTE ROUTE DEPTH MAP DEPTH MAP DEPTH (RAW) ROUTE CONTOUR LINES

Slide 56

Slide 56 text

@hschwentner Is There an App for It?

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

CYBER

Slide 60

Slide 60 text

No content

Slide 61

Slide 61 text

No content

Slide 62

Slide 62 text

No content

Slide 63

Slide 63 text

No content

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

No content

Slide 66

Slide 66 text

@hschwentner Software != End in itself

Slide 67

Slide 67 text

No content

Slide 68

Slide 68 text

?

Slide 69

Slide 69 text

No content

Slide 70

Slide 70 text

IMPORTANT!

Slide 71

Slide 71 text

No content

Slide 72

Slide 72 text

Software Domain

Slide 73

Slide 73 text

Foto: Rosie the Riveter/Wikimedia/CC-PD-Mark

Slide 74

Slide 74 text

No content

Slide 75

Slide 75 text

Domain Knowledg e Foto: Rosie the Riveter/Wikimedia/CC-PD-Mark

Slide 76

Slide 76 text

No content

Slide 77

Slide 77 text

Groß Klein

Slide 78

Slide 78 text

Collaborative Modeling

Slide 79

Slide 79 text

Domain Expert Developer

Slide 80

Slide 80 text

Knowledge crunching

Slide 81

Slide 81 text

No content

Slide 82

Slide 82 text

@hschwentner Methods

Slide 83

Slide 83 text

No content

Slide 84

Slide 84 text

https://domainstorytelling.org

Slide 85

Slide 85 text

LANGUAGE

Slide 86

Slide 86 text

Fach- sprache Domain Expert Developer

Slide 87

Slide 87 text

=> direct commu- nication telephone game to user dev user dev

Slide 88

Slide 88 text

Ludwig Wi)genstein “Whereof one cannot speak, thereof one must be silent.”

Slide 89

Slide 89 text

Ludwig Wittgenstein »Wovon man nicht sprechen kann, darüber muss man schweigen.«

Slide 90

Slide 90 text

Depth Scale Silhouette Marking Depth Map to move to measure run aground neon yellow

Slide 91

Slide 91 text

Ubiquitous Language

Slide 92

Slide 92 text

Jubikjutuss Lengwitsch

Slide 93

Slide 93 text

PUTS NAVIGATING OFFICER CAPTAIN ASKS FOR 7 SHIP SILHOUETTE ON CARTO- GRAPHER SOUNDING SHIP DEPTH MEASURES 1 SENDS 2 TO CALCULATES 3 DRAW S 4 SENDS 5 DEPTH MAP TO MOVES & TURNS 8 SHIP SILHOUETTE TO FIND 9 DISCUSSES WITH 6 ROUTE ROUTE DEPTH MAP DEPTH MAP DEPTH (RAW) ROUTE CONTOUR LINES

Slide 94

Slide 94 text

SMALL

Slide 95

Slide 95 text

No content

Slide 96

Slide 96 text

class Silhouette { //... }

Slide 97

Slide 97 text

No content

Slide 98

Slide 98 text

class Silhouette { public void moveBy(Length length) //... }

Slide 99

Slide 99 text

No content

Slide 100

Slide 100 text

class Silhouette { public void moveBy(Length length) //... public void turnBy(Angle angle) //... }

Slide 101

Slide 101 text

Erich Gamma “Program to an interface, not to an implementation”

Slide 102

Slide 102 text

class Silhouette { public void setPosition(Position p) //... } ✘

Slide 103

Slide 103 text

Slide 104

Slide 104 text

WARNING SETTERS CAUSE MODEL ANEMIA

Slide 105

Slide 105 text

MOVES & TURNS 8 SHIP SILHOUETTE TO FIND ROUTE NAUTICAL OFFICER «Entity» Silhouette move() turn()

Slide 106

Slide 106 text

Tactical Design

Slide 107

Slide 107 text

No content

Slide 108

Slide 108 text

Entity

Slide 109

Slide 109 text

No content

Slide 110

Slide 110 text

import org.jmolecules.ddd.annotation.*; @Entity public class DepthMap { //... }

Slide 111

Slide 111 text

Value Object

Slide 112

Slide 112 text

Example: Depth

Slide 113

Slide 113 text

import org.jmolecules.ddd.annotation.*; @ValueObject public record Depth(/* ... */)

Slide 114

Slide 114 text

Domain Event

Slide 115

Slide 115 text

MANEUVER PLANNING DEPTHS SOUNDING DEPTH MAP COMPLETED

Slide 116

Slide 116 text

BIG

Slide 117

Slide 117 text

Foto: Rosie the Riveter/Wikimedia/CC-PD-Mark

Slide 118

Slide 118 text

Foto: Rosie the Riveter/Wikimedia/CC-PD-Mark

Slide 119

Slide 119 text

No content

Slide 120

Slide 120 text

No content

Slide 121

Slide 121 text

No content

Slide 122

Slide 122 text

#

Slide 123

Slide 123 text

No content

Slide 124

Slide 124 text

No content

Slide 125

Slide 125 text

Bounded Context

Slide 126

Slide 126 text

#

Slide 127

Slide 127 text

PUTS NAVIGATING OFFICER CAPTAIN ASKS FOR 7 SHIP SILHOUETTE ON CARTO- GRAPHER SOUNDING SHIP DEPTH MEASURES 1 SENDS 2 TO CALCULATES 3 DRAW S 4 SENDS 5 DEPTH MAP TO MOVES & TURNS 8 SHIP SILHOUETTE TO FIND 9 DISCUSSES WITH 6 ROUTE ROUTE DEPTH MAP DEPTH MAP DEPTH (RAW) ROUTE CONTOUR LINES DEPTH MEASURE- MENT MANEUVER PLANNING

Slide 128

Slide 128 text

TIDAL FORE- CAST MANEUVER PLANNING DEPTH MEASUREMENT

Slide 129

Slide 129 text

Ubiquitous Language

Slide 130

Slide 130 text

No content

Slide 131

Slide 131 text

WPS – Workplace Solutions #dddkonkret www.wps.de COLLABORATIVE MODELING Domain-Driven Design concrete

Slide 132

Slide 132 text

26.09.23 //// Seite 235 WPS – Workplace Solutions INHALT DOMÄNE DOMÄNE

Slide 133

Slide 133 text

No content

Slide 134

Slide 134 text

Collaborative Modeling

Slide 135

Slide 135 text

Collaborative Modeling

Slide 136

Slide 136 text

https://www.domainstorytelling.org

Slide 137

Slide 137 text

LEGT NAUTIKER KAPITÄN FRAGT NACH 7 SCHIFFS- SILHOUETTE AUF PEILDIENST PEILSCHIFF TIEFE PEILT 1 SENDET 2 AN BERECHNET 3 ERZ EUGT 4 SENDET 5 PEILPLAN AN VERSCHIEBT & DREHT 8 SCHIFFS- SILHOUETTE UND FINDET 9 MELDET AN 6 ROUTE ROUTE PEILPLAN PEILPLAN TIEFEN- ZAHLEN ROUTE TIEFENLINIEN

Slide 138

Slide 138 text

No content

Slide 139

Slide 139 text

No content

Slide 140

Slide 140 text

@hschwentner Explained

Slide 141

Slide 141 text

@hschwentner Domain Storytelling = Pictographic Language + Workshop Format

Slide 142

Slide 142 text

@hschwentner The Workshop Format

Slide 143

Slide 143 text

@hschwentner The right people

Slide 144

Slide 144 text

No content

Slide 145

Slide 145 text

Storyteller Listeners ! !

Slide 146

Slide 146 text

No content

Slide 147

Slide 147 text

No content

Slide 148

Slide 148 text

@hschwentner DEPTH MAP HANDS OVER NAUTICAL OFFICER CARTOGRAPHER TO “The cartographer sends the depth map to the nautical officer” SENDS

Slide 149

Slide 149 text

Active Listening

Slide 150

Slide 150 text

CONCRETE STORIES VS. ABSTRACT PROCESSES

Slide 151

Slide 151 text

@hschwentner The Pictographic Language

Slide 152

Slide 152 text

@hschwentner ßDraw here Leave some empty space there à Annota3ons and varia3ons Preconditions and assumptions Name of the Domain Story

Slide 153

Slide 153 text

@hschwentner actor work object activity 5 sequence number

Slide 154

Slide 154 text

@hschwentner SHIP SILHOUETTE CAPTAIN MOVES

Slide 155

Slide 155 text

@hschwentner DRAWS MEASURES DEPTH DEPTH MAP

Slide 156

Slide 156 text

@hschwentner SENDS DRAWS DEPTH MAP DEPTH MAP

Slide 157

Slide 157 text

@hschwentner person group IT system

Slide 158

Slide 158 text

ACTORS ONCE/ WORK OBJECTS SEVERAL TIMES PUTS NAUTICAL OFFICER 7 SHIP SILHOUETTE MOVES & TURNS 8 SHIP SILHOUETTE

Slide 159

Slide 159 text

PICTOGRAPHIC LANGUAGE – NO IF/SWITCH/OR actor work object ac3vity 5 sequence number

Slide 160

Slide 160 text

Scenario-based modeling

Slide 161

Slide 161 text

Scenarios Maneuver Planning – The Happy Path Maneuver Planning – Storm Flooding Expected Maneuver Planning – All Berths Full

Slide 162

Slide 162 text

@hschwentner Scope

Slide 163

Slide 163 text

Scope Factors

Slide 164

Slide 164 text

@hschwentner Granularity Point in time Domain Purity

Slide 165

Slide 165 text

Granularity fine- grained coarse- grained x x x x x x x x x x x x x x x x x x

Slide 166

Slide 166 text

@hschwentner A Day at the Beach " Sea Level # Kite Level ☁ Cloud Level % Fish Level & Clam Level Foto: Dennis Hamilton/flickr/CC BY 2.0 Alistair Cockburn

Slide 167

Slide 167 text

Point in Time as-is to-be t

Slide 168

Slide 168 text

Point in Time now optimized t with new system

Slide 169

Slide 169 text

Domain Purity pure digitalized

Slide 170

Slide 170 text

@hschwentner Tools

Slide 171

Slide 171 text

No content

Slide 172

Slide 172 text

PowerPoint

Slide 173

Slide 173 text

@hschwentner

Slide 174

Slide 174 text

https://www.wps.de/modeler/ • https://egon.io

Slide 175

Slide 175 text

@hschwentner Purposes

Slide 176

Slide 176 text

@hschwentner draw boundaries learn language work on requirements implement domain model find shadow IT …

Slide 177

Slide 177 text

@hschwentner More on Domain Storytelling

Slide 178

Slide 178 text

No content

Slide 179

Slide 179 text

More info: https://hschwentner.io

Slide 180

Slide 180 text

26.09.23 //// Seite 327 WPS – Workplace Solutions EXERCISE: Domain Storytelling in Groups

Slide 181

Slide 181 text

WPS – Workplace Solutions #dddkonkret www.wps.de STRATEGIC DESIGN Domain-Driven Design concrete

Slide 182

Slide 182 text

26.09.23 //// Seite 330 WPS – Workplace Solutions ÜBERSICHT DOMÄNE DOMÄNE

Slide 183

Slide 183 text

?

Slide 184

Slide 184 text

?

Slide 185

Slide 185 text

No content

Slide 186

Slide 186 text

No content

Slide 187

Slide 187 text

No content

Slide 188

Slide 188 text

No content

Slide 189

Slide 189 text

No content

Slide 190

Slide 190 text

?

Slide 191

Slide 191 text

?

Slide 192

Slide 192 text

No content

Slide 193

Slide 193 text

@hschwentner “Whoever uses a canonical model has lost control over his life.” – Karl Lagerfeld

Slide 194

Slide 194 text

@hschwentner »Wer ein unternehmensweites Domänenmodell einsetzt, hat die Kontrolle über sein Leben verloren« – Karl Lagerfeld

Slide 195

Slide 195 text

No content

Slide 196

Slide 196 text

!

Slide 197

Slide 197 text

No content

Slide 198

Slide 198 text

#

Slide 199

Slide 199 text

No content

Slide 200

Slide 200 text

No content

Slide 201

Slide 201 text

No content

Slide 202

Slide 202 text

No content

Slide 203

Slide 203 text

Bounded Context

Slide 204

Slide 204 text

#

Slide 205

Slide 205 text

Bewegung Kosmetik # Gefühle

Slide 206

Slide 206 text

PUTS NAVIGATING OFFICER CAPTAIN ASKS FOR 7 SHIP SILHOUETTE ON CARTO-GRAPHER SOUNDING SHIP DEPTH MEASURES 1 SENDS 2 TO CALCULATES 3 DRAW S 4 SENDS 5 DEPTH MAP TO MOVES & TURNS 8 SHIP SLHOETTE TO FIND 9 DISCUSSES WITH 6 ROUTE ROUTE DEPTH MAP DEPTH MAP DEPTH (RAW) ROUTE CONTOUR LINES DEPTH MEASURE- MENT MANEUVER PLANNING

Slide 207

Slide 207 text

@hschwentner Another Example

Slide 208

Slide 208 text

No content

Slide 209

Slide 209 text

No content

Slide 210

Slide 210 text

@hschwentner Do I get a car for this?

Slide 211

Slide 211 text

No content

Slide 212

Slide 212 text

26.09.23 //// Seite 360 WPS – Workplace Solutions

Slide 213

Slide 213 text

26.09.23 //// Seite 361 WPS – Workplace Solutions

Slide 214

Slide 214 text

CUSTOMER TELLS WISH FOR 1 SALES- PERSON SIGNS TO GIVES FOR CONTRACT 3 RISK MANAGER CONTRACT PASSES ON TO 4 CONTRACT VO TES CHECKS CALCU LATES 5 6 7 CALCU- LATES TO 8 2 CAR CREDIT RATING INSTALLMENT CAR RESALE VALUE CONTRACT

Slide 215

Slide 215 text

CUSTOMER SIGNS CONTRACT 3 RISK MANAGER CONTRACT VOTES 7 «Entity» Contract sign() vote()

Slide 216

Slide 216 text

«Entity» Contract sign() vote()

Slide 217

Slide 217 text

«Entity» Contract sign() vote() extend() terminate() sell_to_refinance() …

Slide 218

Slide 218 text

BBOM Foto: Benutzer:Summi/Wikipedia/CC-BY-SA-3.0-migrated

Slide 219

Slide 219 text

No content

Slide 220

Slide 220 text

No content

Slide 221

Slide 221 text

@hschwentner Why is that?

Slide 222

Slide 222 text

No content

Slide 223

Slide 223 text

No content

Slide 224

Slide 224 text

@hschwentner Too big to be understood as a whole

Slide 225

Slide 225 text

No content

Slide 226

Slide 226 text

No content

Slide 227

Slide 227 text

26.09.23 //// Seite 375 WPS – Workplace Solutions CUSTOMER TELLS WISH FOR 1 SALES- PERSON SIGNS TO GIVES FOR CONTRACT 3 RISK MANAGER CONTRACT PASSES ON TO 4 CONTRACT VOTES CHECKS CALCULATES 5 6 7 CALCU- LATES TO 8 2 CAR CREDIT RATING INSTALLMENT CAR RESALE VALUE CONTRACT SALES RISK ASSESSMENT

Slide 228

Slide 228 text

«En$ty» Contract sign() vote() ✘

Slide 229

Slide 229 text

«En$ty» Contract sign() «En$ty» Contract vote()

Slide 230

Slide 230 text

«En$ty» Contract sign() vote() ✘

Slide 231

Slide 231 text

«En$ty» Contract sign() «Entity» Contract vote()

Slide 232

Slide 232 text

«En$ty» Contract sign() «En$ty» Contract vote() SALES RISK ASSESSMENT

Slide 233

Slide 233 text

26.09.23 //// Seite 381 WPS – Workplace Solutions Common heuristics: § Points of no Return (persistent work results) § Boundaries within the process § State changes, that affect the “nature” of a work object (e.g. “contract legally binding,” “shopping cart ordered”) § Departments of the organisation § Contextual language § Different usage of work objects § Triggers at different points in time § NOT: by work objects! HOW TO CUT THE DOMAIN? Foto: Wikipedia/PD-ScottForesman

Slide 234

Slide 234 text

26.09.23 //// Seite 382 WPS – Workplace Solutions

Slide 235

Slide 235 text

26.09.23 //// Seite 383 WPS – Workplace Solutions Team Head Team Tail Team Body Team Legs

Slide 236

Slide 236 text

26.09.23 //// Seite 384 WPS – Workplace Solutions Team Emma Team Berta Team Erna Team Lisl

Slide 237

Slide 237 text

@hschwentner Code Database Team

Slide 238

Slide 238 text

@hschwentner Drawing Boundaries with Domain Storytelling

Slide 239

Slide 239 text

@hschwentner Scope: coarse-grained to-be (optimized) pure

Slide 240

Slide 240 text

Which activities belong together (from an actor’s perspective)?

Slide 241

Slide 241 text

CUSTOMER TELLS WISH FOR 1 SALESPERSON SIGNS TO GIVES FOR CONTRACT 3 RISK MANAGER CONTRACT PASSES ON TO 4 CONTRACT VO TES CHECKS CALCU LATES 5 6 7 CALCU- LATES TO 8 2 CAR CREDIT RATING INSTALLMENT CAR RESALE VALUE CONTRACT SALES RISK ASSESSMENT

Slide 242

Slide 242 text

CUSTOMER TELLS WISH FOR 1 SALESPERSON SIGNS TO GIVES FOR CONTRACT 3 RISK MANAGER CONTRACT PASSES ON TO 4 CONTRACT VO TES CHECKS CALCU LATES 5 6 7 CALCU- LATES TO 8 2 CAR CREDIT RATING INSTALLMENT CAR RESALE VALUE CONTRACT SALES Group the sentences • Boundary around activites and work objects • Keep actors outside boundaries Give a name to the group RISK ASSESSMENT

Slide 243

Slide 243 text

@hschwentner Naming Subdomains Express what is done Verbs turned into nouns Often: -ing-form Anti-pattern: name of work object as name for subdomain

Slide 244

Slide 244 text

@hschwentner Naming Subdomains— Examples Price calculation Risk assess- ment Maneuver planning Customer Car Price Payment Car inspection

Slide 245

Slide 245 text

Indicators: 1) Actor produces result on their own 2) One-way informa$on flow 3) Different triggers ($me vs. on demand) 4) Ac$vi$es suppor$ng something that is not in the picture 5) Difference in language 6) Different use of the same thing Ask your domain experts!

Slide 246

Slide 246 text

26.09.23 //// Seite 406 WPS – Workplace Solutions EXERCISE: Find Bounded Contexts

Slide 247

Slide 247 text

26.09.23 //// Seite 407 WPS – Workplace Solutions BOUNDED CONTEXTS FÜR DAS KINO ABLAUF- PLANUNG KARTEN- VERKAUF BUCH- HALTUNG

Slide 248

Slide 248 text

26.09.23 //// Seite 429 WPS – Workplace Solutions AND NOW? § Core vs Supporting § Event Storming § Taktisches Design § Code/LeasingNinja § Hexagonal/Onion Architecture § Context Mapping § How to split the monolith

Slide 249

Slide 249 text

@hschwentner How to split the monolith

Slide 250

Slide 250 text

1) How should it be? 2) How is it? 3) How to move the “is” to the “ideal”? RISK MANAGE- MENT SALES

Slide 251

Slide 251 text

1) How should it be? 1) Domain Re-Discovery 2) “ideal” context map 2) How is it? 1) Architecture Analysis 2) As-is context map 3) How to move the “is” to the “ideal”? 1) Compare 2) Create List of Refactorings 4) Do the move 1) Extract a suppor$ng domain to learn 2) Then extract core(s)

Slide 252

Slide 252 text

old old old old new new new new “just flip the lever” 1 2 3 4 5 a.k.a. big bang replacement

Slide 253

Slide 253 text

old old old new new new new 2 3 4 5 old 1

Slide 254

Slide 254 text

Strangler Fig Application

Slide 255

Slide 255 text

Strangler Fig Application

Slide 256

Slide 256 text

Lesson: is better than Strangler Fig Application Big Bang Replacement

Slide 257

Slide 257 text

<> Contract sign() SALES RISK ASSESSMENT <> Contract sign() vote() … BIG BALL OF MUD <> Contract vote()

Slide 258

Slide 258 text

Read on: h"ps://hschwentner.io/domain-driven-refactorings

Slide 259

Slide 259 text

@hschwentner Always Microservices?

Slide 260

Slide 260 text

Simon Brown

Slide 261

Slide 261 text

Distributed Big Ball Of Mud Modulith Microservices Monolithic Big Ball Of Mud

Slide 262

Slide 262 text

No content

Slide 263

Slide 263 text

@hschwentner Consulting

Slide 264

Slide 264 text

26.09.23 //// Seite 509 WPS – Workplace Solutions § Subdomänen § Kern (Core Domain) § Unterstützende (Supporting Domain) § Allgemeine (Generic Domain) § Context Mapping § Shared Kernel § Customer/Supplier § Open-Host-Service § Published Language § Separate Ways § Anticorruption Layer § Conformist STRATEGISCHES DESIGN – WEITERE BEGRIFFE

Slide 265

Slide 265 text

WPS – Workplace Solutions #dddkonkret www.wps.de UBIQUITOUS LANGUAGE Domain-Driven Design konkret

Slide 266

Slide 266 text

26.09.23 //// Seite 511 WPS – Workplace Solutions ÜBERSICHT DOMÄNE DOMÄNE

Slide 267

Slide 267 text

“There are only two hard things in Computer Science: cache invalidation and naming things.” Phil Karlton

Slide 268

Slide 268 text

“There are only two hard things in Computer Science: cache invalidation, naming things, and off-by-one errors.” Phil Karlton

Slide 269

Slide 269 text

26.09.23 //// Seite 514 WPS – Workplace Solutions TECHNISCHE SPRACHE Auf den Feature Branch pushen? Den Container hochfahren Ich baue dafür ein Interface

Slide 270

Slide 270 text

26.09.23 //// Seite 515 WPS – Workplace Solutions TECHNISCHE SPRACHE X Class The picture can’t be displayed. Database Server Client O/R-Mapping Inheritance A B Method Interface Linux Windows Eclipse Visual Studio

Slide 271

Slide 271 text

26.09.23 //// Seite 516 WPS – Workplace Solutions DOMÄNEN-SPRACHE – BEISPIEL SCHIFFAHRT Tiefenzahl Maßstab Silhouette Peilplan Markierung Länge ü.a. Breite Baggertoleranz

Slide 272

Slide 272 text

26.09.23 //// Seite 517 WPS – Workplace Solutions DOMÄNEN-SPRACHE – BEISPIEL SCHIFFAHRT Container Containernummer 4300 Kran Twistlock Frachtbrief

Slide 273

Slide 273 text

26.09.23 //// Seite 518 WPS – Workplace Solutions DOMÄNEN-SPRACHE – BEISPIEL SCHACH Brett König Figuren Spieler Schachuhr

Slide 274

Slide 274 text

26.09.23 //// Seite 519 WPS – Workplace Solutions DOMÄNEN-SPRACHE – BEISPIEL SCHACH II Remis Zugzwang Schachmatt Partie Zug Rochade

Slide 275

Slide 275 text

26.09.23 //// Seite 520 WPS – Workplace Solutions Fach- sprache Techno Babble ? MOTIVATION ALLGEGENWÄRTIGE SPRACHE

Slide 276

Slide 276 text

26.09.23 //// Seite 521 WPS – Workplace Solutions Fach- sprache Techno Babble Fach- sprache MOTIVATION ALLGEGENWÄRTIGE SPRACHE

Slide 277

Slide 277 text

26.09.23 //// Seite 522 WPS – Workplace Solutions Fach- sprache Techno Babble MOTIVATION ALLGEGENWÄRTIGE SPRACHE

Slide 278

Slide 278 text

26.09.23 //// Seite 523 WPS – Workplace Solutions Techno Babble Fach- sprache MOTIVATION ALLGEGENWÄRTIGE SPRACHE

Slide 279

Slide 279 text

26.09.23 //// Seite 524 WPS – Workplace Solutions Fach- sprache { Techno Babble } ? MOTIVATION ALLGEGENWÄRTIGE SPRACHE

Slide 280

Slide 280 text

26.09.23 //// Seite 525 WPS – Workplace Solutions Fach- sprache { Fach- sprache } MOTIVATION ALLGEGENWÄRTIGE SPRACHE

Slide 281

Slide 281 text

26.09.23 //// Seite 526 WPS – Workplace Solutions Fach- sprache { Fach- sprache } UBIQUITOUS LANGUAGE public class SchiffsSilhouette { public void verschiebe { … } public void drehe { … } … }

Slide 282

Slide 282 text

26.09.23 //// Seite 527 WPS – Workplace Solutions GEMEINSAME SPRACHE § Fachexperten verstehen keine Begriffe zu technischen Umsetzungen § Fachexperten sprechen den Jargon ihrer Domäne, der für Außenstehende wiederum schwer verständlich sein kann è Eine gemeinsame Sprache ist notwendig! § Welche soll es sein? § Die der Entwickler? § Die der Fachexperten? § Etwas dazwischen? èPrinzip von DDD: „Verwende eine Sprache die auf dem Domänenmodell basiert“

Slide 283

Slide 283 text

26.09.23 //// Seite 528 WPS – Workplace Solutions ALLGEGENWÄRTIGE SPRACHE § Verwende die gemeinsame Sprache in.. § der Kommunikation § mündlich § schriftlich § grafisch § im Code § Im Grunde genommen überall è Deswegen nennt sich die Sprache allgegenwärtig.

Slide 284

Slide 284 text

26.09.23 //// Seite 529 WPS – Workplace Solutions SPRACHE TAUCHT NICHT EINFACH AUF § Es braucht Wochen bis Monate... § harter Arbeit § und scharfem Fokus § … um die Schlüsselkonzepte offenzulegen. § Die ersten Wörter einer allgegenwärtigen Sprache kommen üblicherweise direkt aus der Domäne § Im Laufe der Entwicklung werden neue Begriffe definiert und hinzugefügt

Slide 285

Slide 285 text

26.09.23 //// Seite 530 WPS – Workplace Solutions DOMÄNEN-SPRACHE Brett König Figuren Spieler Schachuhr

Slide 286

Slide 286 text

26.09.23 //// Seite 531 WPS – Workplace Solutions UBIQIUTOUS LANGUAGE Brett Figuren Spieler

Slide 287

Slide 287 text

26.09.23 //// Seite 532 WPS – Workplace Solutions UBIQUITOUS LANGUAGE – ITERATION 2 Figuren Spieler Nichtmenschlicher Spieler Brett

Slide 288

Slide 288 text

26.09.23 //// Seite 533 WPS – Workplace Solutions SPRACHEN SIND LEBENDIG § Experimentiere mit alternativen Ausdrucksformen § Das Modell und die Sprache entwickeln sich weiter § Überarbeite dann den Code § Benenne Klassen, Methoden, Module § Entspreche dem neuen Modell § Eine Sprache will gesprochen werden: § Beseitige Unklarheiten durch Konversation

Slide 289

Slide 289 text

No content

Slide 290

Slide 290 text

No content

Slide 291

Slide 291 text

No content

Slide 292

Slide 292 text

http://www.domainstorytelling.or

Slide 293

Slide 293 text

No content

Slide 294

Slide 294 text

26.09.23 //// Seite 539 WPS – Workplace Solutions GLOSSAR § Fachsprache der Benutzer/Ubiquitous Language •bereits existierende Begriffe •rekonstruierte Begriffe •neue Begriffsbildungen • Wer tut was damit wozu? § Kernkonzepte § Wichtiger am Anfang des Projektes § Oft Wegwerfprodukt

Slide 295

Slide 295 text

26.09.23 //// Seite 540 WPS – Workplace Solutions GLOSSAR – BEISPIELDOMÄNE SCHACH SPIELER EINE VON ZWEI PERSONEN, DIE FIGUREN AUF DEM BRETT BEWEGT. KÖNIG EINE EINMALIGE FIGUR, DIE NUR EIN FELD PRO ZUG BEWEGT WERDEN KANN. WENN DER KÖNIG SCHACHMATT GESETZT WURDE, IST DAS SPIEL VORBEI. Beschreibung Begriff Oberbegriff Unterscheidungs- merkmale

Slide 296

Slide 296 text

26.09.23 //// Seite 541 WPS – Workplace Solutions § Ein Team spricht eine eigene Sprache § è Familiensprache, Dialekt § Gleiche Begriffe können (leicht) unterschiedliche Bedeutung haben § Sprache und Modell sind eng gekoppelt JEDER BOUNDED CONTEXT HAT SEINE EIGENE UBIQUITOUS LANGUAGE TIEFEN- MESSUNG PEIL- SCHIFF TIEFEN- ZAHL MARKIER- UNG PEIL- PLAN TIEFEN- ZAHL MANÖVERPLANUNG

Slide 297

Slide 297 text

26.09.23 //// Seite 542 WPS – Workplace Solutions JEDER BOUNDED CONTEXT HAT SEIN EIGENES GLOSSAR TIEFENZAHL TIEFE AN EINEM BESTIMMTEN ORT UNTER BERÜCKSICHTIGUNG VON EBBE UND FLUT TIEFENZAHL PER ECHOLOT GEMESSENE TIEFE BEI NORMALNULL MANÖVER- PLANUNG TIEFENMESSUNG

Slide 298

Slide 298 text

26.09.23 //// Seite 543 WPS – Workplace Solutions EXERCISE: FACHLICHE KERNBEGRIFFE IM IST IDENTIFIZIEREN

Slide 299

Slide 299 text

26.09.23 //// Seite 544 WPS – Workplace Solutions KERNBEGRIFFE FÜR DAS KINO Saalplan Vorstellung Reservierungs- nummer Kinokarte Saalplanstapel Liste der Reservierungs- nummern Gesamtablauf- plan Tagesablaufplan Film Platz/Sitzplatz Saal/Kinosaal Werbung Veranstaltung Eisverkauf Vorführung ? ?

Slide 300

Slide 300 text

26.09.23 //// Seite 545 WPS – Workplace Solutions BOUNDED CONTEXTS FÜR DAS KINO Saalplan Vorstellung Reservierungs- nummer Kinokarte Saalplanstapel Liste der Reservierungs- nummern Gesamtablauf- plan Tagesablaufplan Film Platz/Sitzplatz Saal/Kinosaal Werbung Veranstaltung Eisverkauf Vorführung Kartenverkauf Ablaufplanung

Slide 301

Slide 301 text

26.09.23 //// Seite 546 WPS – Workplace Solutions REDUKTION AUF BOUNDED CONTEXT »KARTENVERKAUF« Saalplan Vorstellung Reservierungs- nummer Kinokarte Saalplanstapel Liste der Reservierungs- nummern Gesamtablauf- plan Tagesablaufplan Film Platz/Sitzplatz Saal/Kinosaal Werbung Veranstaltung Eisverkauf Vorführung Kartenverkauf Ablaufplanung

Slide 302

Slide 302 text

26.09.23 //// Seite 547 WPS – Workplace Solutions REDUKTION AUF BOUNDED CONTEXT »KARTENVERKAUF« Saalplan Vorstellung Reservierungs- nummer Kinokarte Saalplanstapel Liste der Reservierungs- nummern Film Platz/Sitzplatz Saal/Kinosaal

Slide 303

Slide 303 text

26.09.23 //// Seite 548 WPS – Workplace Solutions REDUKTION AUF BOUNDED CONTEXT »KARTENVERKAUF« Saalplan Vorstellung Reservierungs- nummer Kinokarte Saalplanstapel Liste der Reservierungs- nummern Film Platz/Sitzplatz Saal/Kinosaal

Slide 304

Slide 304 text

26.09.23 //// Seite 549 WPS – Workplace Solutions REDUKTION AUF BOUNDED CONTEXT »KARTENVERKAUF« Saalplan Vorstellung Reservierungs- nummer Kinokarte Saalplanstapel Liste der Reservierungs- nummern Film Platz/Sitzplatz Saal/Kinosaal

Slide 305

Slide 305 text

WPS – Workplace Solutions #dddkonkret www.wps.de FACHLICHE HANDLUNGEN Domain-Driven Design hands-on

Slide 306

Slide 306 text

26.09.23 //// Seite 551 WPS – Workplace Solutions ÜBERSICHT DOMÄNE DOMÄNE

Slide 307

Slide 307 text

26.09.23 //// Seite 552 WPS – Workplace Solutions § Durch die Fachexperten (domain experts) § Sie wissen § Worum es bei ihrer Arbeit geht § Wo die Software sie unterstützen kann èWer die Fachlichkeit nicht versteht, kann ihr nicht helfen èSoftwareentwickler und Fachexperten bilden zusammen das Team WIE LERNEN WIR DIE FACHLICHKEIT? Foto: Brandon Raile/Wikipedia

Slide 308

Slide 308 text

26.09.23 //// Seite 553 WPS – Workplace Solutions WIE KOMMEN WIR AN DAS WISSEN DER FACHEXPERTEN? Techniken: § Interviews § Szenarios § Event Storming § Domain Storytelling Das wollen wir extrahieren! Foto: Brandon Raile/Wikipedia Fach- wissen

Slide 309

Slide 309 text

26.09.23 //// Seite 554 WPS – Workplace Solutions WORKSHOPS MIT ANWENDERN UND PRODUCT OWNERS “Georgia?” by The Library of Congress, flickr.com • Teilnehmer aus verschiedenen Bereichen (Business, IT, Management, …) • ein Moderator für den Workshop à direktes Feedback von allen Beteiligten

Slide 310

Slide 310 text

26.09.23 //// Seite 555 WPS – Workplace Solutions EVENT STORMING § Eine Methode um Geschäftsprozesse zu modellieren § Modelliert werden: § Domain Events § Commands § Akteure § Aggregates

Slide 311

Slide 311 text

26.09.23 //// Seite 556 WPS – Workplace Solutions Akteur Arbeitsgegenstand /Arbeitsergebnis Handlung DOMAIN STORYTELLING

Slide 312

Slide 312 text

CUSTOMER TELLS WISH FOR 1 SALES-PERSON SIGNS TO GIVES FOR CONTRACT 3 RISIK MANAGER CONTRACT PASSES ON TO 4 CONTRACT VOTES CHECKS CALCULATES 5 6 7 CALCU- LATES TO 8 2 CAR CREDIT RATING INSTALLMENT CAR RESALE VALUE CONTRACT

Slide 313

Slide 313 text

CUSTOMER SIGNS CONTRACT 3 RISIK MANAGER CONTRACT VOTES 7 «Entity» LeasingContract sign() vote()

Slide 314

Slide 314 text

EXERCISE: FACHLICHE HANDLUNGEN IM IST IDENTIFIZIEREN

Slide 315

Slide 315 text

26.09.23 //// Seite 560 WPS – Workplace Solutions FACHLICHE HANDLUNGEN IM KARTENVERKAUF Saalplan • Anzahl Plätze suchen • Verkaufte Plätze mark. • Reserv. Plätze mit RN markieren Vorstellung Reservierungs- nummer Kinokarte • Mit Platz beschriften Saalplanstapel • Saalplan zu Vorst. Holen • Saalplan zurücklegen Liste der Reservierungsnummern • Reservierungsnummer abholen • Name+Vorst. Vermerken • Vorst. Mit RN heraussuchen Film Platz/Sitzplatz Saal/Kinosaal

Slide 316

Slide 316 text

26.09.23 //// Seite 561 WPS – Workplace Solutions EINIGE DATEN ERGÄNZEN Vorstellung • Datum • Zeitraum • Film Kinokarte • Mit Platz beschriften • Vorstellung Film • Titel • Regisseur, Schauspieler • Freigabe • Spieldauer Platz/Sitzplatz • Reihe • Nummer Saal/Kinosaal • Kapazität • Anzahl Reihen Saalplan • Anzahl Plätze suchen • Verkaufte Plätze mark. • Reserv. Plätze mit RN markieren Reservierungs- nummer Saalplanstapel • Saalplan zu Vorst. Holen • Saalplan zurücklegen Liste der Reservierungsnummern • Reservierungsnummer abholen • Name+Vorst. Vermerken • Vorst. Mit RN heraussuchen

Slide 317

Slide 317 text

WPS – Workplace Solutions #dddkonkret www.wps.de TACTICAL DESIGN Domain-Driven Design concrete

Slide 318

Slide 318 text

26.09.23 //// Seite 563 WPS – Workplace Solutions OVERVIEW DOMÄNE DOMÄNE

Slide 319

Slide 319 text

26.09.23 //// Seite 564 WPS – Workplace Solutions ARCHITECTURE WITH BOUNDED CONTEXTS TIDAL FORECAST MANEUVER PLANNING DEPTHS MEASUREMENT

Slide 320

Slide 320 text

26.09.23 //// Seite 565 WPS – Workplace Solutions ARCHITECTURE WITHIN A BOUNDED CONTEXT MANEUVER PLANNING User Interface Application Domain Infrastructure

Slide 321

Slide 321 text

26.09.23 //// Seite 566 WPS – Workplace Solutions DOMAIN-DRIVEN DESIGN—LAYER ARCHITECTURE § User interface layer § Receives input and user commands and presents information. § Application layer (Fowler: Service Layer) § Describes and coordinates application processes. § Domain layer § Represents the business domain logic. § Infrastructure layer § Provides technical services such as persistence or communication with other systems. User Interface Application Domain Infrastructure

Slide 322

Slide 322 text

26.09.23 //// Seite 567 WPS – Workplace Solutions LAYER ARCHITECTURE – CRITIQUE MANEUVER PLANNING § Domain layer is linked to the database layer § Technology “bubbles up” into domain layer § No clean separation of domain & technology Alistair Cockburn Foto: Fotograf Dennis Hamilton/Alistair Cockburn/flickr/CC BY 2.0 User Interface Application Domain Infrastructure

Slide 323

Slide 323 text

26.09.23 //// Seite 568 WPS – Workplace Solutions below above FROM ABOVE/BELOW TO INSIDE/OUTSIDE out- side inside

Slide 324

Slide 324 text

26.09.23 //// Seite 569 WPS – Workplace Solutions port port HEXAGONAL ARCHITECTURE Foto: Dennis Hamilton/flickr/CC BY 2.0 http://alistair.cockburn.us/Hexagonal%2Barchitecture adapter adapter Alistair Cockburn

Slide 325

Slide 325 text

26.09.23 //// Seite 570 WPS – Workplace Solutions KINDS OF PORTS - For UI etc. - Methods to be called - “from above” - For DB and infrastructure - Interfaces to be implemented - “from below”

Slide 326

Slide 326 text

26.09.23 //// Seite 571 WPS – Workplace Solutions ONION ARCHITECTURE U I “application core” domain services domain model infra app ture struc serv lication ices Jeffrey Palermo !

Slide 327

Slide 327 text

26.09.23 //// Seite 572 WPS – Workplace Solutions CLEAN ARCHITECTURE Robert C. Martin ”Uncle Bob“

Slide 328

Slide 328 text

26.09.23 //// Seite 573 WPS – Workplace Solutions DIE OBJEKTORIENTIERTE GRUNDIDEE: FACHLICHE GEGENSTÄNDE ALS AUSGANGSPUNKT

Slide 329

Slide 329 text

26.09.23 //// Seite 574 WPS – Workplace Solutions FROM DOMAIN STORY TO DOMAIN MODEL Silhouette MOVES SILHOUETTE NAUTICAL OFFICER LENGTH Length moveBy(:Length) BY 8

Slide 330

Slide 330 text

EXERCISE: BUILD DOMAIN MODEL FROM DOMAIN STUDIES IN CASE STUDY

Slide 331

Slide 331 text

26.09.23 //// Seite 576 WPS – Workplace Solutions En##es Value Objects Aggregates Services Factories Repositories

Slide 332

Slide 332 text

26.09.23 //// Seite 577 WPS – Workplace Solutions DOMAIN TERMS – WHAT IS STRIKING? insurance policy vacation request building activity purchase contract order zip code GPS coordinate IBAN container number IATA code

Slide 333

Slide 333 text

26.09.23 //// Seite 579 WPS – Workplace Solutions ENTITIES § Objects of a domain that the user works with. § The results of the work are reflected by their state! § Can be composed of other entities. § Have an (immutable) identity. § Maintain their own consistency and integrity! § Have a clearly defined life cycle. § Have a (mostly mutable) state. § Describe their state by value objects. § Synonyms: Business Object / Domain Object / Work Material § NOT TO BE confused with the term “ENTITY” from Entity-Relationship-Model! Foto: Bundesrepublik Deutschland/Wikipedia/PD Germany Foto: Kaz/pixabay/CC0 Foto: Thomas G./Wikipedia/CC BY-SA 3.0 Foto: OpenClipart-Vectors/pixabay/CC0

Slide 334

Slide 334 text

No content

Slide 335

Slide 335 text

26.09.23 //// Seite 581 WPS – Workplace Solutions ENTITIES «Entity» DepthMap depthMapId mark(Marking)

Slide 336

Slide 336 text

26.09.23 //// Seite 583 WPS – Workplace Solutions VALUE OBJECTS § Value objects are symbols for values of a certain type in the domain. § Symbolize the same value if they are equal. § They are not edited by the user and cannot be modified. § Can be calculated (from other value objects), if necessary. § Can consist of other value objects, but never of entities! ValueObject 2.5 ValueObject ValueObject ValueObject ValueObject two and a half

Slide 337

Slide 337 text

Depth Diameter Position

Slide 338

Slide 338 text

26.09.23 //// Seite 586 WPS – Workplace Solutions VALUE OBJECTS «Value Object» Depth centimeters : int equals()

Slide 339

Slide 339 text

26.09.23 //// Seite 589 WPS – Workplace Solutions EXERCISE: ENTITES, VALUE OBJECTS

Slide 340

Slide 340 text

26.09.23 //// Seite 590 WPS – Workplace Solutions ENTITIES UND VALUE OBJECTS IM KARTENVERKAUF Saalplan • Anzahl Plätze suchen • Verkaufte Plätze mark. • Reserv. Plätze mit RN markieren Vorstellung • Datum • Zeitraum • Film Reservierungs -nummer Kinokarte • Mit Platz beschriften • Vorstellung Saalplanstapel • Saalplan zu Vorst. Holen • Saalplan zurücklegen Liste der Reservierungsnummern • Reservierungsnummer abholen • Name+Vorst. Vermerken • Vorst. Mit RN heraussuchen Film • Titel • Regisseur, Schauspieler • Freigabe • Spieldauer Platz/Sitzplatz • Reihe • Nummer Saal/Kinosaal • Kapazität • Anzahl Reihen VO Entity Entity Entity Entity Entity Entity

Slide 341

Slide 341 text

26.09.23 //// Seite 591 WPS – Workplace Solutions ENTITIES UND VALUE OBJECTS IM KARTENVERKAUF Saalplan • Anzahl Plätze suchen • Verkaufte Plätze mark. • Reserv. Plätze mit RN markieren Vorstellung • Datum • Zeitraum • Film Reservierungs -nummer Liste der Reservierungsnummern • Reservierungsnummer abholen • Name+Vorst. Vermerken • Vorst. Mit RN heraussuchen Film • Titel • Regisseur, Schauspieler • Freigabe • Spieldauer Platz/Sitzplatz • Reihe • Nummer Saal/Kinosaal • Kapazität • Anzahl Reihen VO Entity Entity Entity Entity Entity Entity

Slide 342

Slide 342 text

WPS – Workplace Solutions #dddkonkret www.wps.de REPOSITORIES AND AGGREGATES

Slide 343

Slide 343 text

26.09.23 //// Seite 593 WPS – Workplace Solutions REPOSITORIES § Are the access points to the aggregates! § Encapsulate the technical details of the technical infrastructure layer ... § ... and map external data to entities and value objects. § Store aggregates (e. g. in databases). Repository Aggregate Aggregate Aggregate Aggregate Aggregate

Slide 344

Slide 344 text

26.09.23 //// Seite 594 WPS – Workplace Solutions REPOSITORY @ HAMBURG PORT: THE DEPTH MAP CABINET

Slide 345

Slide 345 text

26.09.23 //// Seite 595 WPS – Workplace Solutions REPOSITORY: TWO PART IMPLEMENTATION «Repository Interface» DepthMapCabinet getDepthMap(Area, Scale) : DepthMap putBack(DepthMap) «Repository Implementation» MySQLDepthMapCabinet

Slide 346

Slide 346 text

26.09.23 //// Seite 596 WPS – Workplace Solutions AGGREGATES § Aggregates are entities that are relevant in themselves (and not just as part of another entity). § Protect the consistency and integrity of their inner entities. § They don't necessarily have to hide them to do this! § Always have a designated entity as an entry point (root). § Usually stored. § As a whole! § Not necessarily in a relational way! Root Entity VO VO VO Aggregate

Slide 347

Slide 347 text

26.09.23 //// Seite 597 WPS – Workplace Solutions AGGREGATES § Actually, the value objects are outside as they are immutable and may be reused anywhere. Root Entity VO VO VO Some other object Aggregate

Slide 348

Slide 348 text

26.09.23 //// Seite 598 WPS – Workplace Solutions AGGREGATES § An aggregate can consist of many entities. Root Entity Entity Entity Entity Entity VO VO VO VO VO VO VO VO VO VO VO Aggregate

Slide 349

Slide 349 text

No content

Slide 350

Slide 350 text

26.09.23 //// Seite 600 WPS – Workplace Solutions Aggregate «Aggregate Root» DepthMap «Entity» Marking «Value Object» Depth

Slide 351

Slide 351 text

26.09.23 //// Seite 601 WPS – Workplace Solutions ENTITIES UND VALUE OBJECTS IM KARTENVERKAUF Saalplan • Anzahl Plätze suchen • Verkaufte Plätze mark. • Reserv. Plätze mit RN markieren Vorstellung • Datum • Zeitraum • Film Reservierungs -nummer Liste der Reservierungsnummern • Reservierungsnummer abholen • Name+Vorst. Vermerken • Vorst. Mit RN heraussuchen Film • Titel • Regisseur, Schauspieler • Freigabe • Spieldauer Platz/Sitzplatz • Reihe • Nummer Saal/Kinosaal • Kapazität • Anzahl Reihen VO Entity Entity Entity Entity Entity Entity

Slide 352

Slide 352 text

EXERCISE: DRAW AGGREGATE BOUNDARIES. WHICH REPOSITORIES DO WE NEED?

Slide 353

Slide 353 text

26.09.23 //// Seite 603 WPS – Workplace Solutions ENTITIES UND VALUE OBJECTS IM KARTENVERKAUF Saalplan • Anzahl Plätze suchen • Verkaufte Plätze mark. • Reserv. Plätze mit RN markieren Vorstellung • Datum • Zeitraum • Film Reservierungs -nummer Liste der Reservierungsnummern • Reservierungsnummer abholen • Name+Vorst. Vermerken • Vorst. Mit RN heraussuchen Film • Titel • Regisseur, Schauspieler • Freigabe • Spieldauer Platz/Sitzplatz • Reihe • Nummer Saal/Kinosaal • Kapazität • Anzahl Reihen VO Entity Entity Wurzel-Entity Entity Entity Entity Aggregate Aggregate Aggregate Aggregate Aggregate

Slide 354

Slide 354 text

WPS – Workplace Solutions #dddkonkret www.wps.de IMPLEMENTING THE BUILDING BLOCKS IN JAVA Domain-Driven Design concrete

Slide 355

Slide 355 text

26.09.23 //// Seite 622 WPS – Workplace Solutions

Slide 356

Slide 356 text

26.09.23 //// Seite 623 WPS – Workplace Solutions A BANK ACCOUNT—FIRST DRAFT public class Account { }

Slide 357

Slide 357 text

26.09.23 //// Seite 624 WPS – Workplace Solutions A BANK ACCOUNT—FIRST DRAFT import org.jmolecules.ddd.annotation.Entity; @Entity public class Account { }

Slide 358

Slide 358 text

26.09.23 //// Seite 625 WPS – Workplace Solutions A BANK ACCOUNT—FIRST DRAFT import org.jmolecules.ddd.annotation.Entity; @Entity public class Account { }

Slide 359

Slide 359 text

26.09.23 //// Seite 626 WPS – Workplace Solutions A BANK ACCOUNT—FIRST DRAFT @Entity public class Account { private int _balance; public int getBalance() { return _balance; } public void setBalance(int balance) { _balance = balance; } } ✘ Bad: The account balance can be set to any value

Slide 360

Slide 360 text

26.09.23 //// Seite 627 WPS – Workplace Solutions A BANK ACCOUNT—SECOND VERSION @Entity public class Account { private int _balance; public int balance() { return _balance; } public void deposit(int amount) { _balance += amount; } public void withdraw(int amount) { _balance -= amount; } } Better: Operations with domain-specific behavior and names

Slide 361

Slide 361 text

26.09.23 //// Seite 628 WPS – Workplace Solutions A BANK ACCOUNT—THIRD VERSION @Entity public class Account { private int _balance; public int balance() { return _balance; } public void deposit(int amount) { _balance += amount; } public void withdraw(int amount) { if (amount > balance()) { throw new IllegalArgumentException("Amount too big"); } _balance -= amount; } Even better: Preconditions can be checked

Slide 362

Slide 362 text

26.09.23 //// Seite 630 WPS – Workplace Solutions DESIGN BY CONTRACT Foto: Urheber Fuchsias/Bertrand Meyer/Wikipedia/CC BY-SA 4.0

Slide 363

Slide 363 text

26.09.23 //// Seite 631 WPS – Workplace Solutions A BANK ACCOUNT—DESIGN BY CONTRACT USING “ASSERT” @Entity public class Account { // ... public void withdraw(int amount) { assert amount <= balance(); _balance -= amount; } } Assertion using keyword assert

Slide 364

Slide 364 text

26.09.23 //// Seite 632 WPS – Workplace Solutions A BANK ACCOUNT—DESIGN BY CONTRACT USING “VALID4J” import static org.valid4j.Assertive.*; @Entity public class Account { // ... public void withdraw(int amount) { require(amount <= balance()); _balance -= amount; } } Hamcrest matchers can be used

Slide 365

Slide 365 text

26.09.23 //// Seite 636 WPS – Workplace Solutions GREAT, BUT… @Entity public class Account { // ... public void withdraw(int amount) { assert amount <= balance(); _balance -= amount; } } Can I withdraw a negative amount? In EUR or GBP or…?

Slide 366

Slide 366 text

26.09.23 //// Seite 638 WPS – Workplace Solutions AN AMOUNT TYPE public class Amount { }

Slide 367

Slide 367 text

26.09.23 //// Seite 639 WPS – Workplace Solutions AN AMOUNT TYPE import org.jmolecules.ddd.annotation.ValueObject; @ValueObject public class Amount { }

Slide 368

Slide 368 text

26.09.23 //// Seite 640 WPS – Workplace Solutions AN AMOUNT TYPE @ValueObject public class Amount { private int _amount; private Currency _currency; }

Slide 369

Slide 369 text

26.09.23 //// Seite 641 WPS – Workplace Solutions AN AMOUNT TYPE @ValueObject public class Amount { private final int _amount; private final Currency _currency; }

Slide 370

Slide 370 text

26.09.23 //// Seite 642 WPS – Workplace Solutions AN AMOUNT TYPE @ValueObject public class Amount { private final int _amount; private final Currency _currency; public Amount(int amount, Currency currency) { _amount = amount; _currency = currency; } }

Slide 371

Slide 371 text

26.09.23 //// Seite 643 WPS – Workplace Solutions AN AMOUNT TYPE @ValueObject public class Amount { private final int _amount; private final Currency _currency; private Amount(int amount, Currency currency) { _amount = amount; _currency = currency; } public static Amount of(int amount, Currency currency) { return new Amount(amount, currency); } }

Slide 372

Slide 372 text

26.09.23 //// Seite 644 WPS – Workplace Solutions AN AMOUNT TYPE @ValueObject public class Amount { private final int _amount; private final Currency _currency; public Amount(int amount, Currency currency) { _amount = amount; _currency = currency; } @Override public boolean equals(Object other) { return _amount == ((Amount) other)._amount && _currency.equals(((Amount) other)._currency); } }

Slide 373

Slide 373 text

26.09.23 //// Seite 645 WPS – Workplace Solutions AN AMOUNT TYPE @ValueObject public class Amount { private final int _amount; private final Currency _currency; public Amount(int amount, Currency currency) { _amount = amount; _currency = currency; } @Override public boolean equals(Object other) { return _amount == ((Amount) other)._amount && _currency.equals(((Amount) other)._currency); } // hashCode() }

Slide 374

Slide 374 text

26.09.23 //// Seite 646 WPS – Workplace Solutions AN AMOUNT TYPE—JAVA 14 AND HIGHER @ValueObject public record Amount(int amount, Currency currency);

Slide 375

Slide 375 text

26.09.23 //// Seite 647 WPS – Workplace Solutions AN AMOUNT TYPE @ValueObject public class Amount { private final int _amount; private final Currency _currency; public Amount(int amount, Currency currency) { _amount = amount; _currency = currency; } public Amount add(Amount otherAmount) { return Amount.of(_amount + otherAmount._amount, _currency); } } The new value object type behaves correctly

Slide 376

Slide 376 text

26.09.23 //// Seite 648 WPS – Workplace Solutions AN AMOUNT TYPE @ValueObject public class Amount { private final int _amount; private final Currency _currency; public Amount(int amount, Currency currency) { _amount = amount; _currency = currency; } public Amount add(Amount otherAmount) { assert hasSameCurrency(otherAmount); return Amount.of(_amount + otherAmount._amount, _currency); } public boolean hasSameCurrency(Amount otherAmount) { return otherAmount._currency == _currency; ... and contracts ensure the correct currency

Slide 377

Slide 377 text

26.09.23 //// Seite 652 WPS – Workplace Solutions A BANK ACCOUNT—FOURTH VERSION @Entity public class Account { private Amount _balance; public Amount balance() { return _balance; } public void deposit(Amount amount) { _balance = _balance.add(amount); } public void withdraw(Amount amount) { assert amount.isLessOrEqual(balance()); _balance = _balance.subtract(amount); } } Now we can use the amount type

Slide 378

Slide 378 text

26.09.23 //// Seite 653 WPS – Workplace Solutions A BANK ACCOUNT—FOURTH VERSION @Entity public class Account { private Amount _balance; public Amount balance() { return _balance; } public void deposit(Amount amount) { _balance = _balance.add(amount); } public void withdraw(Amount amount) { assert amount.hasSameCurrency(balance()); assert amount.isLessOrEqual(balance()); _balance = _balance.subtract(amount); } } ... and define new contracts

Slide 379

Slide 379 text

26.09.23 //// Seite 654 WPS – Workplace Solutions A BANK ACCOUNT—EVENT SOURCED @Entity public class Account { private List _transactions; public Amount balance() { // sum up _transactions } public void deposit(Amount amount) { _transactions.append(new Deposition(amount)); } public void withdraw(Amount amount) { assert amount.hasSameCurrency(balance()); assert amount.isLessOrEqual(balance()); _transactions.append(new Withdrawal(amount)); } } History instead of current status

Slide 380

Slide 380 text

26.09.23 //// Seite 657 WPS – Workplace Solutions IDENTITY OF ENTITIES § In Java, every object has an identity § Namely its reference. § It's a technical identity. § An entity has a identity from a domain perspective § Different technical objects can represent the same entity § In different processes: e.g. on the client / on the server § When they are stored and later read from the database. § The identity can be implemented in two ways: § explicitly (e.g. IBAN) by using a unique key the user is aware of § implicitly (e.g. UUID / GUID) by using a technical key hidden from the user ?

Slide 381

Slide 381 text

26.09.23 //// Seite 658 WPS – Workplace Solutions A BANK ACCOUNT—WITH EXPLICIT IDENTITY @Entity public class Account { @Identity private final IBAN _iban; public Account(IBAN iban) { _iban = iban; } @Override public boolean equals(Object other) { return _iban.equals(((Account)other)._iban); } // ... } The identity is immutable The key is of course a value object The implementation of equals() is based on the identity

Slide 382

Slide 382 text

26.09.23 //// Seite 659 WPS – Workplace Solutions HOW CAN A NEW IDENTITY BE CREATED? § Database § Pro: Central § Can sometimes be created “lazily” § A system-wide value type factory § Domain-specific keys known to the user § Often implemented by the repository of a corresponding aggregate type the key is used for § A UUID / GUID generator § Pro: can be generated independently on any server or client § Con: String in a special format

Slide 383

Slide 383 text

26.09.23 //// Seite 660 WPS – Workplace Solutions BANK TRANSFER—BY DOMAIN SERVICE @Service public class CreditTransferService { public void transfer(Account source, Account destination, Amount amount) { source.withdraw(amount); destination.deposit(amount); } } No fields à stateless

Slide 384

Slide 384 text

EXERCISE: MOBPROGRAMMING @ THE CINEMA

Slide 385

Slide 385 text

26.09.23 //// Seite 663 WPS – Workplace Solutions EVERY BOUNDED CONTEXT HAS ITS OWN GLOSSARY—REVISITED DEPTH DEPTH AT A SPECIFIC GEO POSITION CONSIDERING THE CURRENT TIDAL LEVEL DEPTH DEPTH BELOW SEA LEVEL MEASURED BY ECHO SOUNDER MANEUVER PLANNING DEPTH MEASUREMENT

Slide 386

Slide 386 text

26.09.23 //// Seite 664 WPS – Workplace Solutions EVERY BOUNDED CONTEXT HAS ITS OWN IMPLEMENTATION public struct Depth { public Depth( int depthBelowSeaLevel, int tideLevel) { // ... } } MANEUVER PLANNING DEPTH MEASUREMENT public class Depth { public Depth( int centimeter, LocalDate soundingDate) { // ... } }

Slide 387

Slide 387 text

WPS – Workplace Solutions #dddkonkret www.wps.de IMPLEMENTING THE BUILDING BLOCKS IN C# Domain-Driven Design concrete

Slide 388

Slide 388 text

26.09.23 //// Seite 666 WPS – Workplace Solutions

Slide 389

Slide 389 text

26.09.23 //// Seite 667 WPS – Workplace Solutions A BANK ACCOUNT—FIRST DRAFT public class Account { }

Slide 390

Slide 390 text

26.09.23 //// Seite 668 WPS – Workplace Solutions A BANK ACCOUNT—FIRST DRAFT using NMolecules.DDD; [Entity] public class Account { }

Slide 391

Slide 391 text

26.09.23 //// Seite 669 WPS – Workplace Solutions A BANK ACCOUNT—FIRST DRAFT [Entity] public class Account { public int Balance { get; set; } } ✘ Bad: The account balance can be set to any value

Slide 392

Slide 392 text

26.09.23 //// Seite 670 WPS – Workplace Solutions A BANK ACCOUNT—SECOND VERSION [Entity] public class Account { public int Balance { get; private set; } public void Deposit(int amount) { Balance += amount; } public void Withdraw(int amount) { Balance -= amount; } } Better: Operations with domain-specific behavior and names

Slide 393

Slide 393 text

26.09.23 //// Seite 671 WPS – Workplace Solutions A BANK ACCOUNT—THIRD VERSION [Entity] public class Account { public int Balance { get; private set; } public void Deposit(int amount) { Balance += amount; } public void Withdraw(int amount) { if (amount > balance()) { throw new ArgumentException("Amount too big"); } Balance -= amount; } Even better: Preconditions can be checked

Slide 394

Slide 394 text

26.09.23 //// Seite 673 WPS – Workplace Solutions DESIGN BY CONTRACT Foto: Urheber Fuchsias/Bertrand Meyer/Wikipedia/CC BY-SA 4.0

Slide 395

Slide 395 text

26.09.23 //// Seite 674 WPS – Workplace Solutions A BANK ACCOUNT—DESIGN BY CONTRACT USING “ASSERT” using static System.Diagnostics.Debug; [Entity] public class Account { // ... public void Withdraw(int amount) { Assert(amount <= balance()); Balance -= amount; } } Assertion using Debug.Assert

Slide 396

Slide 396 text

26.09.23 //// Seite 677 WPS – Workplace Solutions GREAT, BUT… using static System.Diagnostics.Debug; [Entity] public class Account { // ... public void Withdraw(int amount) { Assert(amount <= balance()); Balance -= amount; } } Can I withdraw a negative amount? In EUR or GBP or…?

Slide 397

Slide 397 text

26.09.23 //// Seite 679 WPS – Workplace Solutions AN AMOUNT TYPE public class Amount { }

Slide 398

Slide 398 text

26.09.23 //// Seite 680 WPS – Workplace Solutions AN AMOUNT TYPE using NMolecules.DDD; [ValueObject] public class Amount { }

Slide 399

Slide 399 text

26.09.23 //// Seite 681 WPS – Workplace Solutions AN AMOUNT TYPE [ValueObject] public class Amount { private int _amount; private Currency _currency; }

Slide 400

Slide 400 text

26.09.23 //// Seite 682 WPS – Workplace Solutions AN AMOUNT TYPE [ValueObject] public class Amount { private readonly int _amount; private readonly Currency _currency; }

Slide 401

Slide 401 text

26.09.23 //// Seite 683 WPS – Workplace Solutions AN AMOUNT TYPE [ValueObject] public class Amount { private readonly int _amount; private readonly Currency _currency; public Amount(int amount, Currency currency) { _amount = amount; _currency = currency; } }

Slide 402

Slide 402 text

26.09.23 //// Seite 684 WPS – Workplace Solutions AN AMOUNT TYPE [ValueObject] public class Amount { private readonly int _amount; private readonly Currency _currency; private Amount(int amount, Currency currency) { _amount = amount; _currency = currency; } public static Amount Of(int amount, Currency currency) { return new Amount(amount, currency); } }

Slide 403

Slide 403 text

26.09.23 //// Seite 685 WPS – Workplace Solutions AN AMOUNT TYPE [ValueObject] public class Amount { private readonly int _amount; private readonly Currency _currency; // ... public override bool Equals(object other) { return other is Amount && _amount == ((Amount) other)._amount && _currency.Equals(((Amount) other)._currency); } }

Slide 404

Slide 404 text

26.09.23 //// Seite 686 WPS – Workplace Solutions AN AMOUNT TYPE [ValueObject] public class Amount { private readonly int _amount; private readonly Currency _currency; // ... public override bool Equals(object other) => other is Amount && _amount == ((Amount) other)._amount && _currency.Equals(((Amount) other)._currency); }

Slide 405

Slide 405 text

26.09.23 //// Seite 687 WPS – Workplace Solutions AN AMOUNT TYPE [ValueObject] public class Amount { private readonly int _amount; private readonly Currency _currency; // ... public override bool Equals(object other) => other is Amount && _amount == ((Amount) other)._amount && _currency.Equals(((Amount) other)._currency); // GetHashCode() }

Slide 406

Slide 406 text

26.09.23 //// Seite 688 WPS – Workplace Solutions AN AMOUNT TYPE [ValueObject] public class Amount { private readonly int _amount; private readonly Currency _currency; // ... public static bool operator ==(Amount a, Amount b) => a.Equals(b); }

Slide 407

Slide 407 text

26.09.23 //// Seite 689 WPS – Workplace Solutions AN AMOUNT TYPE [ValueObject] public class Amount { private readonly int _amount; private readonly Currency _currency; // ... public static bool operator ==(Amount a, SignDate b) => a.Equals(b); public static bool operator !=(Amount a, SignDate b) => !a.Equals(b); }

Slide 408

Slide 408 text

No content

Slide 409

Slide 409 text

26.09.23 //// Seite 691 WPS – Workplace Solutions 3 CLASSES DEFINE REFERENCE TYPES

Slide 410

Slide 410 text

26.09.23 //// Seite 692 WPS – Workplace Solutions 3 STRUCTS DEFINE VALUE TYPES

Slide 411

Slide 411 text

26.09.23 //// Seite 693 WPS – Workplace Solutions AN AMOUNT TYPE [ValueObject] public struct Amount { private readonly int _amount; private readonly Currency _currency; public Amount(int amount, Currency currency) { _amount = amount; _currency = currency; } }

Slide 412

Slide 412 text

26.09.23 //// Seite 694 WPS – Workplace Solutions AN AMOUNT TYPE [ValueObject] public struct Amount { private readonly int _amount; private readonly Currency _currency; public Amount(int amount, Currency currency) { _amount = amount; _currency = currency; } // Equals() does not have to be overridden }

Slide 413

Slide 413 text

26.09.23 //// Seite 695 WPS – Workplace Solutions AN AMOUNT TYPE [ValueObject] public struct Amount { private readonly int _amount; private readonly Currency _currency; public Amount(int amount, Currency currency) { _amount = amount; _currency = currency; } // but the operators have to be overridden }

Slide 414

Slide 414 text

@hschwentner equals() ! == "

Slide 415

Slide 415 text

26.09.23 //// Seite 697 WPS – Workplace Solutions AN AMOUNT TYPE—C# 9 AND HIGHER [ValueObject] public record Amount(int amount, Currency currency);

Slide 416

Slide 416 text

26.09.23 //// Seite 698 WPS – Workplace Solutions AN AMOUNT TYPE—C# 9 AND HIGHER [ValueObject] public record Amount(int amount, Currency currency); // automatically readonly // Equals(), GetHashCode(), ToString(), operators // do not have to be overloaded and work as expected

Slide 417

Slide 417 text

26.09.23 //// Seite 699 WPS – Workplace Solutions AN AMOUNT TYPE—C# 9 AND HIGHER [ValueObject] public record struct Amount(int amount, Currency currency);

Slide 418

Slide 418 text

26.09.23 //// Seite 700 WPS – Workplace Solutions AN AMOUNT TYPE—C# 10 AND HIGHER [ValueObject] public readonly record struct Amount(int amount, Currency currency);

Slide 419

Slide 419 text

26.09.23 //// Seite 701 WPS – Workplace Solutions AN AMOUNT TYPE [ValueObject] public readonly record struct Amount(int _amount, Currency _currency) { public Amount Add(Amount otherAmount) { return Amount.of(_amount + otherAmount._amount, _currency); } } The new value object type behaves correctly

Slide 420

Slide 420 text

26.09.23 //// Seite 702 WPS – Workplace Solutions AN AMOUNT TYPE [ValueObject] public readonly record struct Amount(int amount, Currency currency) { public Amount Add(Amount otherAmount) { Assert(HasSameCurrency(otherAmount)); return Amount.of(_amount + otherAmount.amount, currency); } public boolean HasSameCurrency(Amount otherAmount) => otherAmount.currency == currency; } ... and contracts ensure the correct currency

Slide 421

Slide 421 text

26.09.23 //// Seite 703 WPS – Workplace Solutions AN AMOUNT TYPE [ValueObject] public readonly record struct Amount(int amount, Currency currency) { public Amount operator +(Amount otherAmount) { Assert(HasSameCurrency(otherAmount)); return Amount.Of(_amount + otherAmount._amount, _currency); } public boolean HasSameCurrency(Amount otherAmount) { return otherAmount._currency == _currency; } }

Slide 422

Slide 422 text

26.09.23 //// Seite 704 WPS – Workplace Solutions A BANK ACCOUNT—FOURTH VERSION [Entity] public class Account { public Amount Balance { get; private set; } public void Deposit(Amount amount) { Balance += amount; } public void Withdraw(Amount amount) { Assert(amount <= Balance); Balance -= amount; } } Now we can use the amount type

Slide 423

Slide 423 text

26.09.23 //// Seite 705 WPS – Workplace Solutions A BANK ACCOUNT—FOURTH VERSION [Entity] public class Account { public Amount Balance { get; private set; } public void Deposit(Amount amount) { Balance += amount; } public void Withdraw(Amount amount) { Assert(amount.HasSameCurrencyAs(Balance); Assert(amount <= Balance); Balance -= amount; } } ... and define new contracts

Slide 424

Slide 424 text

26.09.23 //// Seite 706 WPS – Workplace Solutions A BANK ACCOUNT—EVENT SOURCED @Entity public class Account { private List _transactions; public Amount balance() { // sum up _transactions } public void deposit(Amount amount) { _transactions.append(new Deposition(amount)); } public void withdraw(Amount amount) { assert amount.hasSameCurrency(balance()); assert amount.isLessOrEqual(balance()); _transactions.append(new Withdrawal(amount)); } } History instead of current status

Slide 425

Slide 425 text

26.09.23 //// Seite 709 WPS – Workplace Solutions IDENTITY OF ENTITIES § In Java, every object has an identity § Namely its reference. § It's a technical identity. § An entity has a identity from a domain perspective § Different technical objects can represent the same entity § In different processes: e.g. on the client / on the server § When they are stored and later read from the database. § The identity can be implemented in two ways: § explicitly (e.g. IBAN) by using a unique key the user is aware of § implicitly (e.g. UUID / GUID) by using a technical key hidden from the user ?

Slide 426

Slide 426 text

26.09.23 //// Seite 710 WPS – Workplace Solutions A BANK ACCOUNT—WITH EXPLICIT IDENTITY @Entity public class Account { @Identity private final IBAN _iban; public Account(IBAN iban) { _iban = iban; } @Override public boolean equals(Object other) { return _iban.equals(((Account)other)._iban); } // ... } The identity is immutable The key is of course a value object The implementation of equals() is based on the identity

Slide 427

Slide 427 text

26.09.23 //// Seite 711 WPS – Workplace Solutions HOW CAN A NEW IDENTITY BE CREATED? § Database § Pro: Central § Can sometimes be created “lazily” § A system-wide value type factory § Domain-specific keys known to the user § Often implemented by the repository of a corresponding aggregate type the key is used for § A UUID / GUID generator § Pro: can be generated independently on any server or client § Con: String in a special format

Slide 428

Slide 428 text

26.09.23 //// Seite 712 WPS – Workplace Solutions BANK TRANSFER—BY DOMAIN SERVICE @Service public class CreditTransferService { public void transfer(Account source, Account destination, Amount amount) { source.withdraw(amount); destination.deposit(amount); } } No fields à stateless

Slide 429

Slide 429 text

EXERCISE: MOBPROGRAMMING @ THE CINEMA

Slide 430

Slide 430 text

26.09.23 //// Seite 715 WPS – Workplace Solutions EVERY BOUNDED CONTEXT HAS ITS OWN GLOSSARY—REVISITED DEPTH DEPTH AT A SPECIFIC GEO POSITION CONSIDERING THE CURRENT TIDAL LEVEL DEPTH DEPTH BELOW SEA LEVEL MEASURED BY ECHO SOUNDER MANEUVER PLANNING DEPTH MEASUREMENT

Slide 431

Slide 431 text

26.09.23 //// Seite 716 WPS – Workplace Solutions EVERY BOUNDED CONTEXT HAS ITS OWN IMPLEMENTATION public struct Depth { public Depth( int depthBelowSeaLevel, int tideLevel) { // ... } } MANEUVER PLANNING DEPTH MEASUREMENT public class Depth { public Depth( int centimeter, LocalDate soundingDate) { // ... } }

Slide 432

Slide 432 text

WPS – Workplace Solutions #dddkonkret www.wps.de IMPLEMENTING THE BUILDING BLOCKS IN PHP Domain-Driven Design concrete

Slide 433

Slide 433 text

26.09.23 //// Seite 718 WPS – Workplace Solutions

Slide 434

Slide 434 text

26.09.23 //// Seite 719 WPS – Workplace Solutions A BANK ACCOUNT—FIRST DRAFT class Account { }

Slide 435

Slide 435 text

26.09.23 //// Seite 720 WPS – Workplace Solutions A BANK ACCOUNT—FIRST DRAFT use PHPMolecules\DDD\Attribute\Entity; #[Entity] class Account { }

Slide 436

Slide 436 text

26.09.23 //// Seite 721 WPS – Workplace Solutions A BANK ACCOUNT—FIRST DRAFT #[Entity] class Account { private int $balance; public function getBalance(): int { return $this->balance; } public function setBalance(int $balance): void { $this-> balance = $balance; } } ✘ Bad: The account balance can be set to any value

Slide 437

Slide 437 text

26.09.23 //// Seite 722 WPS – Workplace Solutions A BANK ACCOUNT—SECOND VERSION #[Entity] class Account { private int $balance; public funtion balance(): int { return $this->balance; } public function deposit(int amount): void { $this->balance += amount; } public function withdraw(int amount): void { $this->balance -= amount; } } Better: Operations with domain-specific behavior and names

Slide 438

Slide 438 text

26.09.23 //// Seite 723 WPS – Workplace Solutions A BANK ACCOUNT—THIRD VERSION Even better: Preconditions can be checked #[Entity] class Account { private int $balance; public funtion balance(): int { return $this->balance; } public function deposit(int amount): void { $this->balance += amount; } public function withdraw(int amount): void { assert(amount <= $this->balance()); $this->balance -= amount; }

Slide 439

Slide 439 text

26.09.23 //// Seite 725 WPS – Workplace Solutions DESIGN BY CONTRACT Foto: Urheber Fuchsias/Bertrand Meyer/Wikipedia/CC BY-SA 4.0

Slide 440

Slide 440 text

26.09.23 //// Seite 726 WPS – Workplace Solutions DESIGN BY CONTRACT IN PHP § https://github.com/php-deal § http://www.terminally-incoherent.com/blog/2008/06/05/design-by-contract-in-php-with-assertions/

Slide 441

Slide 441 text

26.09.23 //// Seite 727 WPS – Workplace Solutions GREAT, BUT… #[Entity] class Account { // ... public function withdraw(int $amount): void { assert($amount <= $this->balance()); $this->balance -= $amount; } } Can I withdraw a negative amount? In EUR or GBP or…?

Slide 442

Slide 442 text

26.09.23 //// Seite 729 WPS – Workplace Solutions AN AMOUNT TYPE class Amount { }

Slide 443

Slide 443 text

26.09.23 //// Seite 730 WPS – Workplace Solutions AN AMOUNT TYPE use PHPMolecules\DDD\Attribute\ValueObject; #[ValueObject] class Amount { }

Slide 444

Slide 444 text

26.09.23 //// Seite 731 WPS – Workplace Solutions AN AMOUNT TYPE #[ValueObject] class Amount { private int $amount; private Currency $currency; }

Slide 445

Slide 445 text

26.09.23 //// Seite 732 WPS – Workplace Solutions AN AMOUNT TYPE #[ValueObject] class Amount { private readonly int $amount; private readonly Currency $currency; }

Slide 446

Slide 446 text

26.09.23 //// Seite 734 WPS – Workplace Solutions AN AMOUNT TYPE #[ValueObject] class Amount { private readonly int $amount; private readonly Currency $currency; public function __construct(int $amount, Currency $currency) { $this->amount = $amount; $this->currency = $currency; } }

Slide 447

Slide 447 text

26.09.23 //// Seite 735 WPS – Workplace Solutions AN AMOUNT TYPE—PHP 8.1 AND HIGHER #[ValueObject] class Amount { public function __construct( private readonly int $amount, private readonly Currency $currency ) {} }

Slide 448

Slide 448 text

26.09.23 //// Seite 736 WPS – Workplace Solutions AN AMOUNT TYPE—PHP 8.2 AND HIGHER #[ValueObject] readonly class Amount { public function __construct( private int $amount; private Currency $currency; ) {} }

Slide 449

Slide 449 text

26.09.23 //// Seite 737 WPS – Workplace Solutions AN AMOUNT TYPE #[ValueObject] readonly class Amount { private function __construct( private int $amount, private Currency $currency ) {} public static function of(int $amount, Currency $currency): Amount { return new Amount($amount, $currency); } }

Slide 450

Slide 450 text

26.09.23 //// Seite 738 WPS – Workplace Solutions AN AMOUNT TYPE #[ValueObject] readonly class Amount { public function __construct( private int $amount; private Currency $currency; ) {} public function equals(Amount $other): bool { return $this->amount === $other->amount && $this->currency->equals($other->currency); } }

Slide 451

Slide 451 text

26.09.23 //// Seite 741 WPS – Workplace Solutions AN AMOUNT TYPE #[ValueObject] readonly class Amount { public function __construct( private int $amount, private Currency $currency ) {} public function add(Amount $otherAmount): Amount { return Amount.of($this->amount + $otherAmount->amount, $this->currency); } } The new value object type behaves correctly

Slide 452

Slide 452 text

26.09.23 //// Seite 742 WPS – Workplace Solutions AN AMOUNT TYPE #[ValueObject] readonly class Amount { public function __construct( private int $amount, private Currency $currency ) {} public function add(Amount $otherAmount): Amount { assert($this->hasSameCurrencyAs($otherAmount)); return Amount.of($this->amount + $otherAmount->amount, $this->currency); } public function hasSameCurrencyAs(Amount $otherAmount): bool { return $this->currency === $otherAmount->currency; } } ... and contracts ensure the correct currency

Slide 453

Slide 453 text

26.09.23 //// Seite 743 WPS – Workplace Solutions A BANK ACCOUNT—FOURTH VERSION Now we can use the amount type #[Entity] class Account { private Amount $balance; public function balance(): Amount { return $this->balance; } public function deposit(Amount $amount): void { $this->balance = $this->balance->add($amount); } public function withdraw(Amount $amount): void { assert($amount.isLessOrEqual($this->balance()); $this->balance = $this->balance->subtract($amount); }

Slide 454

Slide 454 text

26.09.23 //// Seite 744 WPS – Workplace Solutions #[Entity] class Account { private Amount $balance; public function balance(): Amount { return $this->balance; } public function deposit(Amount $amount): void { $this->balance = $this->balance->add($amount); } public function withdraw(Amount $amount): void { assert $amount.hasSameCurrency($this->balance()); assert($amount.isLessOrEqual($this->balance()); $this->balance = $this->balance->subtract($amount); A BANK ACCOUNT—FOURTH VERSION ... and define new contracts

Slide 455

Slide 455 text

26.09.23 //// Seite 745 WPS – Workplace Solutions A BANK ACCOUNT—EVENT SOURCED @Entity public class Account { private List _transactions; public Amount balance() { // _transactions aufsummieren } public void deposit(Amount amount) { _transactions.append(new Deposition(amount)); } public void withdraw(Amount amount) { assert amount.hasSameCurrency(balance()); assert amount.isLessOrEqual(balance()); _transactions.append(new Withdrawal(amount)); } } History instead of current status

Slide 456

Slide 456 text

26.09.23 //// Seite 748 WPS – Workplace Solutions IDENTITY OF ENTITIES § In Java, every object has an identity § Namely its reference. § It's a technical identity. § An entity has a identity from a domain perspective § Different technical objects can represent the same entity § In different processes: e.g. on the client / on the server § When they are stored and later read from the database. § The identity can be implemented in two ways: § explicitly (e.g. IBAN) by using a unique key the user is aware of § implicitly (e.g. UUID / GUID) by using a technical key hidden from the user ?

Slide 457

Slide 457 text

26.09.23 //// Seite 749 WPS – Workplace Solutions A BANK ACCOUNT—USING A UNIQUE KEY @Entity public class Account { @Identity private final IBAN _iban; public Account(IBAN iban) { _iban = iban; } @Override public boolean equals(Object other) { return _iban.equals(((Account)other)._iban); } // ... } The identity is immutable The key is of course a value object The implementation of equals () is based on the unique key

Slide 458

Slide 458 text

26.09.23 //// Seite 750 WPS – Workplace Solutions HOW CAN A NEW UNIQUE KEY BE CREATED? § Database § Pro: Central § Can sometimes be created “lazily” § A system-wide value type factory § Domain-specific keys known to the user § Often implemented by the repository of a corresponding aggregate type the key is used for § A UUID / GUID generator § Pro: can be generated independently on any server or client § Con: String in a special format

Slide 459

Slide 459 text

26.09.23 //// Seite 751 WPS – Workplace Solutions BANK TRANSFER—BY DOMAIN SERVICE @Service public class CreditTransferService { public void transfer(Account source, account destination, Amount amount) { source.withdraw(amount); destination.deposit(amount); } } No fields à stateless

Slide 460

Slide 460 text

EXERCISE: MOBPROGRAMMING @ THE CINEMA

Slide 461

Slide 461 text

26.09.23 //// Seite 754 WPS – Workplace Solutions EVERY BOUNDED CONTEXT HAS ITS OWN GLOSSARY—REVISITED DEPTH DEPTH AT A SPECIFIC GEO POSITION CONSIDERING THE CURRENT TIDAL LEVEL DEPTH DEPTH BELOW SEA LEVEL MEASURED BY ECHO SOUNDER MANEUVER- PLANNING SOUNDING SERVICE

Slide 462

Slide 462 text

26.09.23 //// Seite 755 WPS – Workplace Solutions EVERY BOUNDED CONTEXT HAS ITS OWN IMPLEMENTATION public struct Depth { public Depth( int depthBelowSeaLevel, int tideLevel) { // ... } } MANEUVER- PLANNING SOUNDING SERVICE public class Depth { public Depth( int centimeter, LocalDate soundingDate) { // ... } }

Slide 463

Slide 463 text

No content

Slide 464

Slide 464 text

@hschwentner What now?

Slide 465

Slide 465 text

@hschwentner Further topics: Ubiquitous Language Tactical Design (Entity, Value Object, Aggregate, Repository, Service)

Slide 466

Slide 466 text

@hschwentner Consulting

Slide 467

Slide 467 text

Workshop Domain-Driven Design konkret wps.de/ddd

Slide 468

Slide 468 text

No content

Slide 469

Slide 469 text

@hschwentner LeasingNinja.io

Slide 470

Slide 470 text

@hschwentner Literature

Slide 471

Slide 471 text

Foto: H. Schwentner

Slide 472

Slide 472 text

Conways Law Blue Book Red Book 2015 ’16 ’17 ’14 ’13 ’12 2010 ’11 ’09 ’08 ’07 ’06 2005 ’04 ’03 ’02 2000 01 1968 ... ’99 ’98 ’19 2020 ’18

Slide 473

Slide 473 text

No content

Slide 474

Slide 474 text

Buy it online: https://hschwentner.io

Slide 475

Slide 475 text

No content

Slide 476

Slide 476 text

No content

Slide 477

Slide 477 text

@hschwentner FEEDBACK

Slide 478

Slide 478 text

No content

Slide 479

Slide 479 text

No content

Slide 480

Slide 480 text

@hschwentner Bibliography Brandolini, Alberto. Introducing EventStorming. Self-published, Leanpub. Cockburn, Alistair. “Hexagonal Architecture.” January 4, 2005. https://alistair.cockburn.us/hexagonal-architecture/. Conway, Melvin E. “How Do Committees Invent?” Datamation 14, no. 5 (April 1968): 28–31. Evans, Eric. Domain-Driven Design: Tackling Complexity in the Heart of Software. Boston: Addison-Wesley, 2004. Foote, Brian and Joseph Yoder. “Big Ball of Mud.” PLoP ’97, Monticello, IL, September 1997. Fowler, Martin. Patterns of Enterprise Application Architecture. Boston: Addison- Wesley, 2003. Fowler, Martin. “Strangler Fig Application.” Bliki, June 29, 2004. Hofer, Stefan and Henning Schwentner. Domain Storytelling: a Collaborative, Visual, and Agile Way to Develop Domain-Driven Software. Boston: Addison-Wesley, 2022.

Slide 481

Slide 481 text

No content

Slide 482

Slide 482 text

Henning Schwentner ⌂ https://hschwentner.io @hschwentner [email protected]