ddd dirty harry style

158
Dirty Harry’s Style @ziobrando DDD giovedì 23 maggio 13

Post on 18-Sep-2014

17 views

Category:

Technology


0 download

DESCRIPTION

Sometimes you want to do Domain-Driven Design, but the bad guys are against you. Sometimes you need tobe the bad guy. This is Domain-Driven Design in a bloody brownfield scenario.

TRANSCRIPT

Page 1: DDD Dirty Harry style

Dirty Harry’sStyle

@ziobrando

DDD

giovedì 23 maggio 13

Page 2: DDD Dirty Harry style

Goal #1

Domain-Driven Design NOT starting from scratch

giovedì 23 maggio 13

Page 3: DDD Dirty Harry style

Goal #2

Arrive to DDD in a non prescriptive fashion

giovedì 23 maggio 13

Page 4: DDD Dirty Harry style

Do you really need me?giovedì 23 maggio 13

Page 5: DDD Dirty Harry style

Checkpoint

When to apply DDD?- Complex problem- High expectations

giovedì 23 maggio 13

Page 6: DDD Dirty Harry style

Anti-pattern

I want to do DDDI don’t know DDD well...

...so I apply DDD to a simple problem

I don’t see any advantage...DDD is useless.

giovedì 23 maggio 13

Page 7: DDD Dirty Harry style

Wrong

giovedì 23 maggio 13

Page 8: DDD Dirty Harry style

We don’t learn in flatlandsgiovedì 23 maggio 13

Page 9: DDD Dirty Harry style

giovedì 23 maggio 13

Page 10: DDD Dirty Harry style

giovedì 23 maggio 13

Page 11: DDD Dirty Harry style

That’s not our job

giovedì 23 maggio 13

Page 12: DDD Dirty Harry style

Call a Bomb Squadgiovedì 23 maggio 13

Page 13: DDD Dirty Harry style

Our Safety Net

✓Environments

✓Build Scripts

✓Test suite

✓Private Database

✓Fixtures

✓Continuous Integration

✓...giovedì 23 maggio 13

Page 14: DDD Dirty Harry style

Toolsgiovedì 23 maggio 13

Page 15: DDD Dirty Harry style

Professionalsgiovedì 23 maggio 13

Page 16: DDD Dirty Harry style

Proper Tools

giovedì 23 maggio 13

Page 17: DDD Dirty Harry style

Even in the worst situationsgiovedì 23 maggio 13

Page 18: DDD Dirty Harry style

giovedì 23 maggio 13

Page 19: DDD Dirty Harry style

Could  you  please  pass  me  

the  ...thing?

The  s5ngy  one?

Yes,  the  one  that  looks  

like  ...  that

giovedì 23 maggio 13

Page 20: DDD Dirty Harry style

Tools

giovedì 23 maggio 13

Page 21: DDD Dirty Harry style

Precision

giovedì 23 maggio 13

Page 22: DDD Dirty Harry style

Contraceptive

Aspirin

giovedì 23 maggio 13

Page 23: DDD Dirty Harry style

Language

giovedì 23 maggio 13

Page 24: DDD Dirty Harry style

Siete

giovedì 23 maggio 13

Page 25: DDD Dirty Harry style

avanscoperta

Checklist

Tools? --> Tool. (always the same)Precision? --> “When you are in state 12, the field MRKT_NFLD can be only B or K”Language? --> :-(

giovedì 23 maggio 13

Page 26: DDD Dirty Harry style

giovedì 23 maggio 13

Page 27: DDD Dirty Harry style

Application

giovedì 23 maggio 13

Page 28: DDD Dirty Harry style

Application

Application

giovedì 23 maggio 13

Page 29: DDD Dirty Harry style

Application

ApplicationApplication

giovedì 23 maggio 13

Page 30: DDD Dirty Harry style

Application

ApplicationApplication

Application

giovedì 23 maggio 13

Page 31: DDD Dirty Harry style

Application

ApplicationApplication

Application

Application

giovedì 23 maggio 13

Page 32: DDD Dirty Harry style

Application

ApplicationApplication

Application

Application

Database

giovedì 23 maggio 13

Page 33: DDD Dirty Harry style

Application

ApplicationApplication

Application

Application

Database

Application

giovedì 23 maggio 13

Page 34: DDD Dirty Harry style

Application

ApplicationApplication

Application

Application

Database

ApplicationApplication

giovedì 23 maggio 13

Page 35: DDD Dirty Harry style

Application

ApplicationApplication

Application

Application

Database

ApplicationApplication

Database

giovedì 23 maggio 13

Page 36: DDD Dirty Harry style

Application

ApplicationApplication

Application

Application

Database

ApplicationApplication

Database

giovedì 23 maggio 13

Page 37: DDD Dirty Harry style

Application

ApplicationApplication

Application

Application

Database

ApplicationApplication

Database

Data-based integrationgiovedì 23 maggio 13

Page 38: DDD Dirty Harry style

avanscoperta

Data-­‐based  integra5on  checklist

Can we tell...

Which application is responsible for the data structure?

Which requirement influenced data definition?

Is it still valid?

It it valid in my context?

Which applications use that data?

Which consequences if we alter the structure?

giovedì 23 maggio 13

Page 39: DDD Dirty Harry style

Goal #1

Arrive to DDD in a brownfield scenario

giovedì 23 maggio 13

Page 40: DDD Dirty Harry style

Solution #1

Put the mess aside and start form a greenfield scenario

giovedì 23 maggio 13

Page 41: DDD Dirty Harry style

Which problem do we want to

solve?

giovedì 23 maggio 13

Page 42: DDD Dirty Harry style

Onegiovedì 23 maggio 13

Page 43: DDD Dirty Harry style

Our

problemgiovedì 23 maggio 13

Page 44: DDD Dirty Harry style

85%

15%

Our PROBLEM domain

past SOLUTIONS

Complexity

giovedì 23 maggio 13

Page 45: DDD Dirty Harry style

Our problem

Il nostro contesto

I nostri dati

I dati da condividere

Altro contesto

Altro contesto

Il nostro database

Language!!

giovedì 23 maggio 13

Page 46: DDD Dirty Harry style

TRESPASSERS WILL BE SHOT

SURVIVORS WILL BE SHOT AGAIN

THIS DATABASE IS MY DATABASE

giovedì 23 maggio 13

Page 47: DDD Dirty Harry style

“Put  in  this  way,  it’s  simple...”

Dev:

giovedì 23 maggio 13

Page 48: DDD Dirty Harry style

giovedì 23 maggio 13

Page 49: DDD Dirty Harry style

DDD helps to solve complex problems,

giovedì 23 maggio 13

Page 50: DDD Dirty Harry style

DDD helps to solve complex problems, NOT to make simple problems complicated

giovedì 23 maggio 13

Page 51: DDD Dirty Harry style

Zombie management

strategies

giovedì 23 maggio 13

Page 52: DDD Dirty Harry style

A fence...giovedì 23 maggio 13

Page 53: DDD Dirty Harry style

Learnt from the Romans

giovedì 23 maggio 13

Page 54: DDD Dirty Harry style

giovedì 23 maggio 13

Page 55: DDD Dirty Harry style

Romulus,  let  me  run  this  query,  

please...

giovedì 23 maggio 13

Page 56: DDD Dirty Harry style

Romulus,  let  me  run  this  query,  

please...

Nope.

giovedì 23 maggio 13

Page 57: DDD Dirty Harry style

Romulus,  let  me  run  this  query,  

please...

Nope.Please,  

Romulus  ...  it’s  a  read-­‐only  one

giovedì 23 maggio 13

Page 58: DDD Dirty Harry style

giovedì 23 maggio 13

Page 59: DDD Dirty Harry style

giovedì 23 maggio 13

Page 60: DDD Dirty Harry style

Bounded Context

giovedì 23 maggio 13

Page 61: DDD Dirty Harry style

Anti-Corruption Layer

getContattiUnici(…):List<Contatto>

<<Service>>ContactService

ContactService

context boundary

AttributoAttributo

<<Value Object>>Contatto

AttributoAttributo

<<Entity>>MyEntity

Our Context ACLcontext boundary

Componente

Other Context

giovedì 23 maggio 13

Page 62: DDD Dirty Harry style

Anti-Corruption Layer

getContattiUnici(…):List<Contatto>

<<Service>>ContactService

ContactService

context boundary

AttributoAttributo

<<Value Object>>Contatto

AttributoAttributo

<<Entity>>MyEntity

Our Context ACLcontext boundary

Componente

Other Context

Model as it should be

giovedì 23 maggio 13

Page 63: DDD Dirty Harry style

Anti-Corruption Layer

getContattiUnici(…):List<Contatto>

<<Service>>ContactService

ContactService

context boundary

AttributoAttributo

<<Value Object>>Contatto

AttributoAttributo

<<Entity>>MyEntity

Our Context ACLcontext boundary

Componente

Other Context

Model as it should be

The legacy component with all its troubles

giovedì 23 maggio 13

Page 64: DDD Dirty Harry style

Anti-Corruption Layer

getContattiUnici(…):List<Contatto>

<<Service>>ContactService

ContactService

context boundary

AttributoAttributo

<<Value Object>>Contatto

AttributoAttributo

<<Entity>>MyEntity

Our Context ACLcontext boundary

Componente

Other Context

Model as it should be

The legacy component with all its troubles

Here we solve the mess, by any possible means.

giovedì 23 maggio 13

Page 65: DDD Dirty Harry style

...and within our Bounded Context...

giovedì 23 maggio 13

Page 66: DDD Dirty Harry style

The ideal modelgiovedì 23 maggio 13

Page 67: DDD Dirty Harry style

It’s not that important...

giovedì 23 maggio 13

Page 68: DDD Dirty Harry style

Compliance

giovedì 23 maggio 13

Page 69: DDD Dirty Harry style

There’s no medal

giovedì 23 maggio 13

Page 70: DDD Dirty Harry style

But maybe...

http://www.youtube.com/watch?v=zDZFcDGpL4Ugiovedì 23 maggio 13

Page 71: DDD Dirty Harry style

DDD as a learning process

giovedì 23 maggio 13

Page 72: DDD Dirty Harry style

DDD patterns support frequent

rewritingsgiovedì 23 maggio 13

Page 73: DDD Dirty Harry style

DDD as an architecture that

supports evolution

giovedì 23 maggio 13

Page 74: DDD Dirty Harry style

...better provide us the right support

tool for design

giovedì 23 maggio 13

Page 75: DDD Dirty Harry style

Whiteboards

giovedì 23 maggio 13

Page 76: DDD Dirty Harry style

CRC Cards

giovedì 23 maggio 13

Page 77: DDD Dirty Harry style

“Can  we  really  do  this?”

P.O.:

giovedì 23 maggio 13

Page 78: DDD Dirty Harry style

giovedì 23 maggio 13

Page 79: DDD Dirty Harry style

“We  need  to  put  a  valida9on  layer  to  avoid  incorrect  data  to  enter  into  the  system”

Dev:

giovedì 23 maggio 13

Page 80: DDD Dirty Harry style

Really?

giovedì 23 maggio 13

Page 81: DDD Dirty Harry style

giovedì 23 maggio 13

Page 82: DDD Dirty Harry style

Complex

validation is a

smell

giovedì 23 maggio 13

Page 83: DDD Dirty Harry style

(almost) same data

Different Behaviour

submitregisterPayment

amountcustomerstate

<<Entity>>Fattura

editvalidate

amountcustomer

<<Entity>>InvoicePreview

giovedì 23 maggio 13

Page 84: DDD Dirty Harry style

Multiple models

giovedì 23 maggio 13

Page 85: DDD Dirty Harry style

Frequent

Archetypes

giovedì 23 maggio 13

Page 86: DDD Dirty Harry style

3 archetypes?

Collaborative constructionTopic+Conversation

Facebook, Basecamp, Github

ExecutionState machines, Commands

TrackingLogging, Auditing, Datawarehouse, Events

giovedì 23 maggio 13

Page 87: DDD Dirty Harry style

Haven’t put “why do all my DDD

application looks the same” online, yet

giovedì 23 maggio 13

Page 88: DDD Dirty Harry style

What does the DBA say?

giovedì 23 maggio 13

Page 89: DDD Dirty Harry style

“I  was  expec9nd  the  DB  structure  to  be  defined  once  for  all...”

DBA:

giovedì 23 maggio 13

Page 90: DDD Dirty Harry style

...

giovedì 23 maggio 13

Page 91: DDD Dirty Harry style

My first idea...

giovedì 23 maggio 13

Page 92: DDD Dirty Harry style

giovedì 23 maggio 13

Page 93: DDD Dirty Harry style

She doesn’t exist in reality

giovedì 23 maggio 13

Page 94: DDD Dirty Harry style

Can a software component designed

before one application be adequate to N

following applications?giovedì 23 maggio 13

Page 95: DDD Dirty Harry style

Obstaclesgiovedì 23 maggio 13

Page 96: DDD Dirty Harry style

giovedì 23 maggio 13

Page 97: DDD Dirty Harry style

You have to watch your back

before interacting with system X

giovedì 23 maggio 13

Page 98: DDD Dirty Harry style

There are some f***ing stored

procedures that run every 10 minutes

giovedì 23 maggio 13

Page 99: DDD Dirty Harry style

Nobody knows exactly how do

they workgiovedì 23 maggio 13

Page 100: DDD Dirty Harry style

Nobody knows exactly how do

they work

Nobody ever changed them and

came back alive

giovedì 23 maggio 13

Page 101: DDD Dirty Harry style

giovedì 23 maggio 13

Page 102: DDD Dirty Harry style

Hrmpf

giovedì 23 maggio 13

Page 103: DDD Dirty Harry style

Risk...giovedì 23 maggio 13

Page 104: DDD Dirty Harry style

Dress  up  properly  before  going  

out! Are  you  wearing  your  T-­‐

shirt?Lock  the  door  when  you  get  out!

Drive  slowly!

giovedì 23 maggio 13

Page 105: DDD Dirty Harry style

Anxiety

giovedì 23 maggio 13

Page 106: DDD Dirty Harry style

Cognitive load

How many

things should

I know, before

touching the

code?

giovedì 23 maggio 13

Page 107: DDD Dirty Harry style

can we be ignorant and

productive at the same time?

giovedì 23 maggio 13

Page 108: DDD Dirty Harry style

Transaction management?

Presentation Layer Application Layer Domain Layer Infrastructure Layer

DDD

99% of ex

ample

sgiovedì 23 maggio 13

Page 109: DDD Dirty Harry style

Repository & SRP

delivery()

pricecustomer

<<Entity>>Order

createOrder(…)delivery(order_ID, …)

<<Facade>>Application Facade

+saveChanges()

<<ORM>>Context

save(Order, Context)findById(id, Context)

<<Repository>>OrderRepository

createEmpty()

<<factory>>OrderFactory

opens / closes

uses

creates

Infrastructure layer

Application LayerDomain Layer

Riceve il contesto transazionale dall'esternoIl Repository effettua le

operazioni di aggiunta e/o rimozione dal contesto, ma è l'application layer ad invocare saveChanges()

Crea il contesto e lo passa al repository

giovedì 23 maggio 13

Page 110: DDD Dirty Harry style

Do not

accept

candies

from

strangers

giovedì 23 maggio 13

Page 111: DDD Dirty Harry style

...why don’t we

set up a shared

database table?...

giovedì 23 maggio 13

Page 112: DDD Dirty Harry style

giovedì 23 maggio 13

Page 113: DDD Dirty Harry style

Ooops...

giovedì 23 maggio 13

Page 114: DDD Dirty Harry style

Do not

accept

candies

from

strangers

giovedì 23 maggio 13

Page 115: DDD Dirty Harry style

Do not accept candies

giovedì 23 maggio 13

Page 116: DDD Dirty Harry style

Motivationsgiovedì 23 maggio 13

Page 117: DDD Dirty Harry style

Difficult childhood

namesurnamephoneNumber

Person

studentCardNumberStudent

subjectstatus

Professor

giovedì 23 maggio 13

Page 118: DDD Dirty Harry style

Show me you’re a

person...giovedì 23 maggio 13

Page 119: DDD Dirty Harry style

...print yourself!

giovedì 23 maggio 13

Page 120: DDD Dirty Harry style

Difficult Childhood

namesurnamephoneNumber

Person

studentCardNumberStudent

subjectstatus

Professor

giovedì 23 maggio 13

Page 121: DDD Dirty Harry style

The two things do not match

...and it’s not an ORM problemgiovedì 23 maggio 13

Page 122: DDD Dirty Harry style

Every architectural rule that starts with “every” is wrong

giovedì 23 maggio 13

Page 123: DDD Dirty Harry style

Consequencesgiovedì 23 maggio 13

Page 124: DDD Dirty Harry style

You see, the worls is divided into two

categories: the one in a Bounded Context, and

the one who digs...

giovedì 23 maggio 13

Page 125: DDD Dirty Harry style

You ...dig!

giovedì 23 maggio 13

Page 126: DDD Dirty Harry style

Estimations

giovedì 23 maggio 13

Page 127: DDD Dirty Harry style

The tile layer

giovedì 23 maggio 13

Page 128: DDD Dirty Harry style

giovedì 23 maggio 13

Page 129: DDD Dirty Harry style

giovedì 23 maggio 13

Page 130: DDD Dirty Harry style

giovedì 23 maggio 13

Page 131: DDD Dirty Harry style

Accounting it right

giovedì 23 maggio 13

Page 132: DDD Dirty Harry style

Accounting it right

Implementing amazing functionalities € 10.000

giovedì 23 maggio 13

Page 133: DDD Dirty Harry style

Accounting it right

Implementing amazing functionalities € 10.000Learning new techniques and tools € 4.000

giovedì 23 maggio 13

Page 134: DDD Dirty Harry style

Accounting it right

Implementing amazing functionalities € 10.000Learning new techniques and tools € 4.000

Establish Safety Conditions € 12.000

giovedì 23 maggio 13

Page 135: DDD Dirty Harry style

Accounting it right

Implementing amazing functionalities € 10.000Learning new techniques and tools € 4.000

Establish Safety Conditions € 12.000Cleaning up somebody else’s mess € 8.000

giovedì 23 maggio 13

Page 136: DDD Dirty Harry style

giovedì 23 maggio 13

Page 137: DDD Dirty Harry style

That  will  cost  you  an  €xtra,  sir...

giovedì 23 maggio 13

Page 138: DDD Dirty Harry style

Value

giovedì 23 maggio 13

Page 139: DDD Dirty Harry style

Value

Don’t forget to count the extra value also.

giovedì 23 maggio 13

Page 140: DDD Dirty Harry style

Estimations

giovedì 23 maggio 13

Page 141: DDD Dirty Harry style

Estimations“Explorative” evolutions

giovedì 23 maggio 13

Page 142: DDD Dirty Harry style

Estimations“Explorative” evolutions

Legacy “Pandora’s box”giovedì 23 maggio 13

Page 143: DDD Dirty Harry style

Ignorance based planning

100 1 2 3 4 5 6 7 8 9

100%

0

10%

20%

30%

40%

50%

60%

70%

80%

90%

Time

Igno

ranc

e

Ignorance

Breakthrough

Ignorance

giovedì 23 maggio 13

Page 144: DDD Dirty Harry style

Gold plating?

giovedì 23 maggio 13

Page 145: DDD Dirty Harry style

Product  Owner

Team

giovedì 23 maggio 13

Page 146: DDD Dirty Harry style

Product  Owner

Team

A  simple  requirement

giovedì 23 maggio 13

Page 147: DDD Dirty Harry style

Product  Owner

Team

A  simple  requirement A  simple  requirement

giovedì 23 maggio 13

Page 148: DDD Dirty Harry style

Product  Owner

Team

A  simple  requirement A  simple  requirement

Done  as  DDD  prescribes

giovedì 23 maggio 13

Page 149: DDD Dirty Harry style

Product  Owner

Team

A  simple  requirement A  simple  requirement

Done  as  DDD  prescribes

In  a  clean  and  elegant  fashion

giovedì 23 maggio 13

Page 150: DDD Dirty Harry style

Product  Owner

Team

A  simple  requirement A  simple  requirement

Done  as  DDD  prescribes

In  a  clean  and  elegant  fashion

Soon

giovedì 23 maggio 13

Page 151: DDD Dirty Harry style

Product  Owner

Team

A  simple  requirement A  simple  requirement

Done  as  DDD  prescribes

In  a  clean  and  elegant  fashion

Soon ....ooops

giovedì 23 maggio 13

Page 152: DDD Dirty Harry style

Yes, but how can I understand if I am

doing DDD?

giovedì 23 maggio 13

Page 153: DDD Dirty Harry style

avanscoperta

Are  we  really  doing  DDD?

Result is better than expectationsNo fear in rewriting piecesWe’re having fun

giovedì 23 maggio 13

Page 154: DDD Dirty Harry style

Questions?

giovedì 23 maggio 13

Page 155: DDD Dirty Harry style

Questions?

Really, you can...

giovedì 23 maggio 13

Page 156: DDD Dirty Harry style

Questions?

giovedì 23 maggio 13

Page 157: DDD Dirty Harry style

Questions?

Really, you can...

giovedì 23 maggio 13