SLIDE 1 Refactoring Toward Deeper Insight
DDD Cologne Bonn Meetup / Jul 2, 2020 Christoph Baudson / @sustainablepace
SLIDE 2 Christoph Baudson
- Software dev at REWE Digital since 08/2015
- Organizer of the DDD Meetup Cologne
- @sustainablepace / sustainablepace.net
SLIDE 3
- 1. Some theory
- 2. Example
- a. The domain
- b. Let’s code!
SLIDE 4 Domain experts Developers
Domain Model
SLIDE 5
Misconception!
Modeling in Domain-Driven Design is a waterfall-like big design up-front, and therefore not agile
SLIDE 6
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 Micro-Refactorings
SLIDE 9 Refactoring to patterns Micro-Refactorings
SLIDE 10 Refactoring to deeper insight Refactoring to patterns Micro-Refactorings
SLIDE 11 Domain experts Developers
Domain Model
SLIDE 12
Misconception!
When doing µServices, doing a rewrite is easy
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
- 1. Some theory
- 2. Example
- a. The domain
- b. Let’s code!
SLIDE 15
SLIDE 16
SLIDE 17
SLIDE 18 Deposit Categories
SLIDE 19
SLIDE 20 Deposit Map
Updates after 2 weeks
SLIDE 21
SLIDE 22
- 1. Some theory
- 2. Example
- a. The domain
- b. Let’s code!
SLIDE 23
SLIDE 24 INFRASTRUCTURE APPLICATION SERVICES DOMAIN
SLIDE 25 Refactoring to patterns Micro-Refactorings
SLIDE 26 INFRASTRUCTURE APPLICATION SERVICES DOMAIN
SLIDE 27
Creates the deposit map, based on the last update.
SLIDE 28
Nullable?
SLIDE 29
Nullable? What does min date mean?
SLIDE 30
Nullable? What does min date mean? Another from date?
SLIDE 31 Nullable? What does min date mean?
- > Nullable input is leaking in from infrastructure
Another from date?
SLIDE 32
Why should a service assemble parts of the Map? I need to think about this...
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 INFRASTRUCTURE APPLICATION SERVICES DOMAIN
SLIDE 35
The boundaries are not enforced. ….and this obscures the business logic. Is there any?
SLIDE 36
Is there anything to be learned from the model?
SLIDE 37
YES! We forgot about another use case ;)
SLIDE 38
- > Let’s add these concepts of the model to the code...
SLIDE 39
- > Let’s add these concepts of the model to the code...
Input is no longer nullable!
SLIDE 40 INFRASTRUCTURE APPLICATION SERVICES DOMAIN
SLIDE 41
- > Null check is moved outwards to infrastructure
SLIDE 42
- > Null check is moved outwards to infrastructure
There is a service for each use case now...
SLIDE 43
Misconception!
Don’t repeat yourself!
SLIDE 44 INFRASTRUCTURE APPLICATION SERVICES DOMAIN
SLIDE 45
- > Let’s move the deposit map creation to the domain
SLIDE 46
Two different public factory methods
SLIDE 47
dataDrop is encapsulated in model Naming could be improved...
SLIDE 48
Data conversion happens in the background
SLIDE 49 INFRASTRUCTURE APPLICATION SERVICES DOMAIN
SLIDE 50
SLIDE 51
Apparently, there is no business logic...
SLIDE 52
Apparently, there is no business logic... Added a new repository method to eliminate nullability...
SLIDE 53
SLIDE 54
There is one business rule that was obscured before...
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 Parameters are not
been eliminated.
SLIDE 57 Refactoring to deeper insight Refactoring to patterns Micro-Refactorings
SLIDE 58
- 1. Some theory
- 2. Example
- a. The domain
- b. Let’s code!
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
Recommendations
SLIDE 61 Let’s learn more about tactical design. Contact me! Questions?
Christoph Baudson / @sustainablepace