Slide 1

Slide 1 text

Getting Modules Right MICHAEL PLÖD FELLOW with Domain Driven Design

Slide 2

Slide 2 text

Get my DDD book cheaper Book Voucher: 7.99 instead of (min) 9.99 http://leanpub.com/ddd-by-example/c/speakerdeck

Slide 3

Slide 3 text

Michael Plöd Fellow at INNOQ Follow me on Twitter under @bitboss Current consulting topics: • Domain-Driven Design • Team Topologies • Transformation from IT Delivery to digital product orgs Regular speaker at (inter-)national conferences and author of a book + various articles

Slide 4

Slide 4 text

Separation of Concerns is the division of complex systems according to responsibility

Slide 5

Slide 5 text

Modularity is a specialization of SoC and about information hiding loose coupling high cohesion

Slide 6

Slide 6 text

Domain Driven Design has great modularization concepts (Bounded Context, Aggregate) and an iterative approach for the identi ication of modules

Slide 7

Slide 7 text

Bounded Context Bounded Context Bounded Context Module Granularity in DDD

Slide 8

Slide 8 text

Bounded Context Bounded Context Bounded Context Module Granularity in DDD Aggregate Aggregate Aggregate Aggregate Aggregate Aggregate Aggregate Aggregate Aggregate

Slide 9

Slide 9 text

Bounded Context Bounded Context Bounded Context Let’s start with Bounded Contexts

Slide 10

Slide 10 text

https://github.com/ddd-crew/ddd-starter-modelling-process

Slide 11

Slide 11 text

https://github.com/ddd-crew/ddd-starter-modelling-process

Slide 12

Slide 12 text

https://github.com/ddd-crew/ddd-starter-modelling-process

Slide 13

Slide 13 text

https://github.com/ddd-crew/ddd-starter-modelling-process

Slide 14

Slide 14 text

„It is not the domain experts knowledge that goes into production, it is the assumption of the developers that goes into production” 11 Alberto Brandolini Inventor of EventStorming

Slide 15

Slide 15 text

A B C „Gut, dass wir alle einer Meinung sind!“ Inspiriert durch Jeff Patton & Luke Barren „good that we all share the same opinion“

Slide 16

Slide 16 text

for doing Domain Driven Design Domain expert knowledge is essential

Slide 17

Slide 17 text

we need direct collaboration

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

How the business names things TV Window Chair Trolley Painting Desk

Slide 20

Slide 20 text

How the business names things TV Window Chair Trolley Painting Desk What we see in code TransparencyFactory RollableStuffContainer EntertainmentProviderSingleton DecoratorImpl RestProvider WorkEnablementDevice

Slide 21

Slide 21 text

DOMAIN MODEL Domain Experts Developers Ubiquitous Language Conversations Code Drawings Documentation

Slide 22

Slide 22 text

Event Storming is a direct collaboration workshop for various stakeholders of a piece of software

Slide 23

Slide 23 text

Chaotic Exploration A Domain Event is the main concept of EventStorming. It is an event that is relevant for the domain experts and contextual for the domain that is being explored. A Domain Event is a verb at the past tense. The of icial EventStorming colour is orange.

Slide 24

Slide 24 text

Enforcing the timeline In a second step we sort those events along a timeline. This will ignite quite a few discussions and may take some time.

Slide 25

Slide 25 text

Pivotal Events & Swimlanes Mark those events that are very important. Those are your pivotal events. You may also highlight parallel streams of activity with swimlanes.

Slide 26

Slide 26 text

Quiz: which of these events are pivotal?

Slide 27

Slide 27 text

Quiz: which of these events are pivotal?

Slide 28

Slide 28 text

23 https://github.com/ddd-crew/ddd-starter-modelling-process

Slide 29

Slide 29 text

Text... Shape... Color... Size... There are many choices to group domain concepts 24 Output quantity

Slide 30

Slide 30 text

Boundaries between Pivotal Events Heuristic: A pivotal event will probably sit on a boundary of a module

Slide 31

Slide 31 text

Mind the swimlanes Heuristic: Swimlanes can help you in identifying further cohesion criteria

Slide 32

Slide 32 text

Bounded Context A Bounded Context is a boundary for a model expressed in a consistent language tailored around a speci ic purpose

Slide 33

Slide 33 text

A Bounded Context is a boundary for a model expressed in a consistent language tailored around a speci ic purpose Boundary Learning and mastering domain complexity Conducting experiments / Learning Delivering high value software

Slide 34

Slide 34 text

A Bounded Context is a boundary for a model expressed in a consistent language tailored around a speci ic purpose Boundary for a model Business Rules Decisions Policies

Slide 35

Slide 35 text

A Bounded Context is a boundary for a model expressed in a consistent language tailored around a speci ic purpose Language Terminology De initions Meaning

Slide 36

Slide 36 text

A fruit or a vegetable? What is a tomato?

Slide 37

Slide 37 text

A fruit or a vegetable? What is a tomato?

Slide 38

Slide 38 text

Fruit Botanics A fruit or a vegetable? What is a tomato?

Slide 39

Slide 39 text

Fruit Botanics Vegetable Cooking A fruit or a vegetable? What is a tomato?

Slide 40

Slide 40 text

Fruit Botanics Vegetable Cooking US Customs A fruit or a vegetable? What is a tomato?

Slide 41

Slide 41 text

Fruit Botanics Vegetable Cooking US Customs 25 Min Time Management A fruit or a vegetable? What is a tomato?

Slide 42

Slide 42 text

Fruit Botanics Vegetable Cooking US Customs 25 Min Time Management Feedback Theater A fruit or a vegetable? What is a tomato?

Slide 43

Slide 43 text

A Bounded Context is a boundary for a model expressed in a consistent language tailored around a speci ic purpose Purpose Language Rules Speci ic Model

Slide 44

Slide 44 text

Botanics-US Customs-Cooking-Time management- Feedback Tomato It aims at speci ic models tied to a speci ic purpose The Bounded Context is not about the

Slide 45

Slide 45 text

Some IT conference Registration of visitors Lunch planning Printing of badges Room planning Selling tickets Handling of payments

Slide 46

Slide 46 text

YOU at some IT conference Registration of visitors Lunch planning Printing of badges Room planning Selling tickets Handling of payments

Slide 47

Slide 47 text

You can group concerns Lunch planning Room planning Event Management Printing of badges Badges Registration of visitors Selling tickets Handling of payments Ticket Sales

Slide 48

Slide 48 text

Don’t Repeat Yourself

Slide 49

Slide 49 text

YOU at some IT conference Registration of visitors Lunch planning Printing of badges Room planning Selling tickets Handling of payments

Slide 50

Slide 50 text

Bounded Context A Bounded Context is a boundary for a model expressed in a consistent language tailored around a speci ic purpose

Slide 51

Slide 51 text

This has no purpose at all and the language is also not speci ic here

Slide 52

Slide 52 text

Maybe those are interesting bounded context candidates? Event Management Badges Ticket Sales

Slide 53

Slide 53 text

Look for terminology Application Form Scoring Rule Cluster Documents Real Estate Veri ication Income Veri ication Rejection Reference Properties Rejection Scoring Rule Cluster Credit Decision Template Credit Decision Hierarchy Contract Proposal Contract Welcome Letter Repayment Plan Decision

Slide 54

Slide 54 text

44 https://github.com/ddd-crew/ddd-starter-modelling-process

Slide 55

Slide 55 text

45 Domain Message Flow Modelling A Domain Message Flow Diagram is a simple visualization showing the low of messages (commands, events, queries) between actors, bounded contexts, and systems, for a single scenario. Source: https://github.com/ddd-crew/domain-message- low-modelling

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

47 https://github.com/ddd-crew/ddd-starter-modelling-process

Slide 58

Slide 58 text

47 https://github.com/ddd-crew/ddd-starter-modelling-process

Slide 59

Slide 59 text

48 Bounded Context Design Canvas The canvas guides you through the process of designing a bounded context by requiring you to consider and make choices about the key elements of its design, from naming to responsibilities, to its public interface and dependencies. Source: https://github.com/ddd-crew/bounded-context-canvas

Slide 60

Slide 60 text

No content

Slide 61

Slide 61 text

COHESION Think about

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

Bounded Context Bounded Context Bounded Context Let’s dig into the Bounded Contexts

Slide 67

Slide 67 text

Bounded Context Bounded Context Bounded Context Let’s dig into the Bounded Contexts Aggregate Aggregate Aggregate Aggregate Aggregate Aggregate Aggregate Aggregate Aggregate

Slide 68

Slide 68 text

56 https://github.com/ddd-crew/ddd-starter-modelling-process

Slide 69

Slide 69 text

Everything from here on is inside a Bounded Context We are now talking about more ine grained modules

Slide 70

Slide 70 text

Aggregates (Internal) Building Blocks Entities Value Objects Factories Services Repositories TACTICAL DESIGN helps us with regards to evolvability of microservices

Slide 71

Slide 71 text

Entities Entities represent the core business objects of a bounded context’s model Each Entity has a constant identity Each Entity has its own lifecycle Customer Credit Application Shipment

Slide 72

Slide 72 text

Value Objects Value Objects derive their identity from their values Value Objects do not have their own lifecycle, they inherit it from Entities that are referencing them You should always consider value objects for your domain model Color Monetary Amount Customer

Slide 73

Slide 73 text

Entity Value Value

Slide 74

Slide 74 text

Entity Value Value Using only Entities and Value Objects you will end up with big object graphs

Slide 75

Slide 75 text

Entity Value Value Aggregates group Entities and Value Objects

Slide 76

Slide 76 text

ROOT ROOT ROOT Value Value ROOT Each Aggregate has a Root Entity, aka Aggregate Root

Slide 77

Slide 77 text

SelfDisclosure Address RedemptionDetail Loan LoanApplicationForm CustomerNumber Customer Consider using Value Objects as indirect references between Aggregates

Slide 78

Slide 78 text

Aggregate Domain Concepts Aggregates represent higher level business concepts. Behavior Try moving behavior to Value Objects in the Aggregates. The Entities should deal with lifecycle and identitiy. Invariants Aggregates allow us to implement and enforce rules and invariants (a incancial situation must have in- and outgoings)

Slide 79

Slide 79 text

Hints Small Prefer small aggregates that usually only contain an Entity and some Value Objects. Consistency Boundaries Take a look which parts of your model must be updated in an atomically consistent manner One TX per Aggregate Aggregates should be updated in separate transactions which leads to eventual consistency Reference by Identity Do not implement direct references to other Root Entities. Prefer referencing to Identity Value Objects

Slide 80

Slide 80 text

Design Level EventStorming helps you to identify and design aggregates

Slide 81

Slide 81 text

Design Level EventStorming

Slide 82

Slide 82 text

Starting point

Slide 83

Slide 83 text

Chaotic Exploration on business rules

Slide 84

Slide 84 text

Which grouping of the rules is the right one?

Slide 85

Slide 85 text

„the key to incremental architecture is to build on a framework that can accommodate change... that framework is the domain.... By modeling the domain, you can more easily handle changes to the domain“ Allen Holub https:/ /holub.com

Slide 86

Slide 86 text

These groups are great candidates for aggregates!

Slide 87

Slide 87 text

OOAD usually starts with nouns as class candidates, then goes to attributes and then verbs (methods) DDD starts with behavior (verbs) and looks then on structures Mind the difference between this approach and the classic object oriented analysis and design (OOAD)

Slide 88

Slide 88 text

No content

Slide 89

Slide 89 text

www.innoq.com Thanks! Michael Plöd Twitter: @bitboss LinkedIn: https://www.linkedin.com/in/michael-ploed/ Get my DDD book at a discount with: https:/ /leanpub.com/ddd-by-example/c/speakerdeck (or by scanning the QR code) Check out https:/ /socreatory.com for DDD trainings with me (onsite or online as well as in German or English)