Refactoring Toward Deeper Insight DDD Cologne Bonn Meetup / Jul 2, - - PowerPoint PPT Presentation

refactoring toward deeper insight
SMART_READER_LITE
LIVE PREVIEW

Refactoring Toward Deeper Insight DDD Cologne Bonn Meetup / Jul 2, - - PowerPoint PPT Presentation

Refactoring Toward Deeper Insight DDD Cologne Bonn Meetup / Jul 2, 2020 Christoph Baudson / @sustainablepace Christoph Baudson Software dev at REWE Digital since 08/2015 Organizer of the DDD Meetup Cologne @sustainablepace /


slide-1
SLIDE 1

Refactoring Toward Deeper Insight

DDD Cologne Bonn Meetup / Jul 2, 2020 Christoph Baudson / @sustainablepace

slide-2
SLIDE 2

Christoph Baudson

  • Software dev at REWE Digital since 08/2015
  • Organizer of the DDD Meetup Cologne
  • @sustainablepace / sustainablepace.net
slide-3
SLIDE 3
  • 1. Some theory
  • 2. Example
  • a. The domain
  • b. Let’s code!
slide-4
SLIDE 4

Domain experts Developers

Domain Model

slide-5
SLIDE 5

Misconception!

Modeling in Domain-Driven Design is a waterfall-like big design up-front, and therefore not agile

slide-6
SLIDE 6
slide-7
SLIDE 7

Insights

  • No one gets the model correct the first time.
  • The model changes over time.
  • The model is never done.
  • The model needs to be refactored

throughout the development lifecycle.

slide-8
SLIDE 8

Micro-Refactorings

slide-9
SLIDE 9

Refactoring to patterns Micro-Refactorings

slide-10
SLIDE 10

Refactoring to deeper insight Refactoring to patterns Micro-Refactorings

slide-11
SLIDE 11

Domain experts Developers

Domain Model

slide-12
SLIDE 12

Misconception!

When doing µServices, doing a rewrite is easy

slide-13
SLIDE 13

Insights

  • The domain knowledge is lost after rewriting
  • All dialogue has to happen all over again.
  • It’s hard to guarantee it will work as before.
  • Doing the same thing twice and expecting

improvements is foolish.

  • The domain model is an asset!
slide-14
SLIDE 14
  • 1. Some theory
  • 2. Example
  • a. The domain
  • b. Let’s code!
slide-15
SLIDE 15
slide-16
SLIDE 16
slide-17
SLIDE 17
slide-18
SLIDE 18

Deposit Categories

slide-19
SLIDE 19
slide-20
SLIDE 20

Deposit Map

Updates after 2 weeks

slide-21
SLIDE 21
slide-22
SLIDE 22
  • 1. Some theory
  • 2. Example
  • a. The domain
  • b. Let’s code!
slide-23
SLIDE 23
slide-24
SLIDE 24

INFRASTRUCTURE APPLICATION SERVICES DOMAIN

slide-25
SLIDE 25

Refactoring to patterns Micro-Refactorings

slide-26
SLIDE 26

INFRASTRUCTURE APPLICATION SERVICES DOMAIN

slide-27
SLIDE 27

Creates the deposit map, based on the last update.

slide-28
SLIDE 28

Nullable?

slide-29
SLIDE 29

Nullable? What does min date mean?

slide-30
SLIDE 30

Nullable? What does min date mean? Another from date?

slide-31
SLIDE 31

Nullable? What does min date mean?

  • > Nullable input is leaking in from infrastructure

Another from date?

slide-32
SLIDE 32

Why should a service assemble parts of the Map? I need to think about this...

slide-33
SLIDE 33

Why should a service assemble parts of the Map? I need to think about this...

  • > The deposit map should be build in the domain
slide-34
SLIDE 34

INFRASTRUCTURE APPLICATION SERVICES DOMAIN

slide-35
SLIDE 35

The boundaries are not enforced. ….and this obscures the business logic. Is there any?

slide-36
SLIDE 36

Is there anything to be learned from the model?

slide-37
SLIDE 37

YES! We forgot about another use case ;)

slide-38
SLIDE 38
  • > Let’s add these concepts of the model to the code...
slide-39
SLIDE 39
  • > Let’s add these concepts of the model to the code...

Input is no longer nullable!

slide-40
SLIDE 40

INFRASTRUCTURE APPLICATION SERVICES DOMAIN

slide-41
SLIDE 41
  • > Null check is moved outwards to infrastructure
slide-42
SLIDE 42
  • > Null check is moved outwards to infrastructure

There is a service for each use case now...

slide-43
SLIDE 43

Misconception!

Don’t repeat yourself!

slide-44
SLIDE 44

INFRASTRUCTURE APPLICATION SERVICES DOMAIN

slide-45
SLIDE 45
  • > Let’s move the deposit map creation to the domain
slide-46
SLIDE 46

Two different public factory methods

slide-47
SLIDE 47

dataDrop is encapsulated in model Naming could be improved...

slide-48
SLIDE 48

Data conversion happens in the background

slide-49
SLIDE 49

INFRASTRUCTURE APPLICATION SERVICES DOMAIN

slide-50
SLIDE 50
slide-51
SLIDE 51

Apparently, there is no business logic...

slide-52
SLIDE 52

Apparently, there is no business logic... Added a new repository method to eliminate nullability...

slide-53
SLIDE 53
slide-54
SLIDE 54

There is one business rule that was obscured before...

slide-55
SLIDE 55

There is one business rule that was obscured before... OK! We send a full map if the categories have been updated :)

slide-56
SLIDE 56

Parameters are not

  • null. Min Date has

been eliminated.

slide-57
SLIDE 57

Refactoring to deeper insight Refactoring to patterns Micro-Refactorings

slide-58
SLIDE 58
  • 1. Some theory
  • 2. Example
  • a. The domain
  • b. Let’s code!
slide-59
SLIDE 59

Afterthoughts

  • It might not be the best example
  • We were merely reminded about domain

concepts we didn’t translate to code

  • It was not a breakthrough
  • But the code is now aligned again with

the domain model! Hexagon ftw!

slide-60
SLIDE 60

Recommendations

slide-61
SLIDE 61

Let’s learn more about tactical design. Contact me! Questions?

Christoph Baudson / @sustainablepace