DDD Dirty Harry style

Preview:

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.

Citation preview

Dirty Harry’sStyle

@ziobrando

DDD

giovedì 23 maggio 13

Goal #1

Domain-Driven Design NOT starting from scratch

giovedì 23 maggio 13

Goal #2

Arrive to DDD in a non prescriptive fashion

giovedì 23 maggio 13

Do you really need me?giovedì 23 maggio 13

Checkpoint

When to apply DDD?- Complex problem- High expectations

giovedì 23 maggio 13

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

Wrong

giovedì 23 maggio 13

We don’t learn in flatlandsgiovedì 23 maggio 13

giovedì 23 maggio 13

giovedì 23 maggio 13

That’s not our job

giovedì 23 maggio 13

Call a Bomb Squadgiovedì 23 maggio 13

Our Safety Net

✓Environments

✓Build Scripts

✓Test suite

✓Private Database

✓Fixtures

✓Continuous Integration

✓...giovedì 23 maggio 13

Toolsgiovedì 23 maggio 13

Professionalsgiovedì 23 maggio 13

Proper Tools

giovedì 23 maggio 13

Even in the worst situationsgiovedì 23 maggio 13

giovedì 23 maggio 13

Could  you  please  pass  me  

the  ...thing?

The  s5ngy  one?

Yes,  the  one  that  looks  

like  ...  that

giovedì 23 maggio 13

Tools

giovedì 23 maggio 13

Precision

giovedì 23 maggio 13

Contraceptive

Aspirin

giovedì 23 maggio 13

Language

giovedì 23 maggio 13

Siete

giovedì 23 maggio 13

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

giovedì 23 maggio 13

Application

giovedì 23 maggio 13

Application

Application

giovedì 23 maggio 13

Application

ApplicationApplication

giovedì 23 maggio 13

Application

ApplicationApplication

Application

giovedì 23 maggio 13

Application

ApplicationApplication

Application

Application

giovedì 23 maggio 13

Application

ApplicationApplication

Application

Application

Database

giovedì 23 maggio 13

Application

ApplicationApplication

Application

Application

Database

Application

giovedì 23 maggio 13

Application

ApplicationApplication

Application

Application

Database

ApplicationApplication

giovedì 23 maggio 13

Application

ApplicationApplication

Application

Application

Database

ApplicationApplication

Database

giovedì 23 maggio 13

Application

ApplicationApplication

Application

Application

Database

ApplicationApplication

Database

giovedì 23 maggio 13

Application

ApplicationApplication

Application

Application

Database

ApplicationApplication

Database

Data-based integrationgiovedì 23 maggio 13

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

Goal #1

Arrive to DDD in a brownfield scenario

giovedì 23 maggio 13

Solution #1

Put the mess aside and start form a greenfield scenario

giovedì 23 maggio 13

Which problem do we want to

solve?

giovedì 23 maggio 13

Onegiovedì 23 maggio 13

Our

problemgiovedì 23 maggio 13

85%

15%

Our PROBLEM domain

past SOLUTIONS

Complexity

giovedì 23 maggio 13

Our problem

Il nostro contesto

I nostri dati

I dati da condividere

Altro contesto

Altro contesto

Il nostro database

Language!!

giovedì 23 maggio 13

TRESPASSERS WILL BE SHOT

SURVIVORS WILL BE SHOT AGAIN

THIS DATABASE IS MY DATABASE

giovedì 23 maggio 13

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

Dev:

giovedì 23 maggio 13

giovedì 23 maggio 13

DDD helps to solve complex problems,

giovedì 23 maggio 13

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

giovedì 23 maggio 13

Zombie management

strategies

giovedì 23 maggio 13

A fence...giovedì 23 maggio 13

Learnt from the Romans

giovedì 23 maggio 13

giovedì 23 maggio 13

Romulus,  let  me  run  this  query,  

please...

giovedì 23 maggio 13

Romulus,  let  me  run  this  query,  

please...

Nope.

giovedì 23 maggio 13

Romulus,  let  me  run  this  query,  

please...

Nope.Please,  

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

giovedì 23 maggio 13

giovedì 23 maggio 13

giovedì 23 maggio 13

Bounded Context

giovedì 23 maggio 13

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

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

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

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

...and within our Bounded Context...

giovedì 23 maggio 13

The ideal modelgiovedì 23 maggio 13

It’s not that important...

giovedì 23 maggio 13

Compliance

giovedì 23 maggio 13

There’s no medal

giovedì 23 maggio 13

But maybe...

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

DDD as a learning process

giovedì 23 maggio 13

DDD patterns support frequent

rewritingsgiovedì 23 maggio 13

DDD as an architecture that

supports evolution

giovedì 23 maggio 13

...better provide us the right support

tool for design

giovedì 23 maggio 13

Whiteboards

giovedì 23 maggio 13

CRC Cards

giovedì 23 maggio 13

“Can  we  really  do  this?”

P.O.:

giovedì 23 maggio 13

giovedì 23 maggio 13

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

Dev:

giovedì 23 maggio 13

Really?

giovedì 23 maggio 13

giovedì 23 maggio 13

Complex

validation is a

smell

giovedì 23 maggio 13

(almost) same data

Different Behaviour

submitregisterPayment

amountcustomerstate

<<Entity>>Fattura

editvalidate

amountcustomer

<<Entity>>InvoicePreview

giovedì 23 maggio 13

Multiple models

giovedì 23 maggio 13

Frequent

Archetypes

giovedì 23 maggio 13

3 archetypes?

Collaborative constructionTopic+Conversation

Facebook, Basecamp, Github

ExecutionState machines, Commands

TrackingLogging, Auditing, Datawarehouse, Events

giovedì 23 maggio 13

Haven’t put “why do all my DDD

application looks the same” online, yet

giovedì 23 maggio 13

What does the DBA say?

giovedì 23 maggio 13

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

DBA:

giovedì 23 maggio 13

...

giovedì 23 maggio 13

My first idea...

giovedì 23 maggio 13

giovedì 23 maggio 13

She doesn’t exist in reality

giovedì 23 maggio 13

Can a software component designed

before one application be adequate to N

following applications?giovedì 23 maggio 13

Obstaclesgiovedì 23 maggio 13

giovedì 23 maggio 13

You have to watch your back

before interacting with system X

giovedì 23 maggio 13

There are some f***ing stored

procedures that run every 10 minutes

giovedì 23 maggio 13

Nobody knows exactly how do

they workgiovedì 23 maggio 13

Nobody knows exactly how do

they work

Nobody ever changed them and

came back alive

giovedì 23 maggio 13

giovedì 23 maggio 13

Hrmpf

giovedì 23 maggio 13

Risk...giovedì 23 maggio 13

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

Anxiety

giovedì 23 maggio 13

Cognitive load

How many

things should

I know, before

touching the

code?

giovedì 23 maggio 13

can we be ignorant and

productive at the same time?

giovedì 23 maggio 13

Transaction management?

Presentation Layer Application Layer Domain Layer Infrastructure Layer

DDD

99% of ex

ample

sgiovedì 23 maggio 13

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

Do not

accept

candies

from

strangers

giovedì 23 maggio 13

...why don’t we

set up a shared

database table?...

giovedì 23 maggio 13

giovedì 23 maggio 13

Ooops...

giovedì 23 maggio 13

Do not

accept

candies

from

strangers

giovedì 23 maggio 13

Do not accept candies

giovedì 23 maggio 13

Motivationsgiovedì 23 maggio 13

Difficult childhood

namesurnamephoneNumber

Person

studentCardNumberStudent

subjectstatus

Professor

giovedì 23 maggio 13

Show me you’re a

person...giovedì 23 maggio 13

...print yourself!

giovedì 23 maggio 13

Difficult Childhood

namesurnamephoneNumber

Person

studentCardNumberStudent

subjectstatus

Professor

giovedì 23 maggio 13

The two things do not match

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

Every architectural rule that starts with “every” is wrong

giovedì 23 maggio 13

Consequencesgiovedì 23 maggio 13

You see, the worls is divided into two

categories: the one in a Bounded Context, and

the one who digs...

giovedì 23 maggio 13

You ...dig!

giovedì 23 maggio 13

Estimations

giovedì 23 maggio 13

The tile layer

giovedì 23 maggio 13

giovedì 23 maggio 13

giovedì 23 maggio 13

giovedì 23 maggio 13

Accounting it right

giovedì 23 maggio 13

Accounting it right

Implementing amazing functionalities € 10.000

giovedì 23 maggio 13

Accounting it right

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

giovedì 23 maggio 13

Accounting it right

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

Establish Safety Conditions € 12.000

giovedì 23 maggio 13

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

giovedì 23 maggio 13

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

giovedì 23 maggio 13

Value

giovedì 23 maggio 13

Value

Don’t forget to count the extra value also.

giovedì 23 maggio 13

Estimations

giovedì 23 maggio 13

Estimations“Explorative” evolutions

giovedì 23 maggio 13

Estimations“Explorative” evolutions

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

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

Gold plating?

giovedì 23 maggio 13

Product  Owner

Team

giovedì 23 maggio 13

Product  Owner

Team

A  simple  requirement

giovedì 23 maggio 13

Product  Owner

Team

A  simple  requirement A  simple  requirement

giovedì 23 maggio 13

Product  Owner

Team

A  simple  requirement A  simple  requirement

Done  as  DDD  prescribes

giovedì 23 maggio 13

Product  Owner

Team

A  simple  requirement A  simple  requirement

Done  as  DDD  prescribes

In  a  clean  and  elegant  fashion

giovedì 23 maggio 13

Product  Owner

Team

A  simple  requirement A  simple  requirement

Done  as  DDD  prescribes

In  a  clean  and  elegant  fashion

Soon

giovedì 23 maggio 13

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

Yes, but how can I understand if I am

doing DDD?

giovedì 23 maggio 13

avanscoperta

Are  we  really  doing  DDD?

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

giovedì 23 maggio 13

Questions?

giovedì 23 maggio 13

Questions?

Really, you can...

giovedì 23 maggio 13

Questions?

giovedì 23 maggio 13

Questions?

Really, you can...

giovedì 23 maggio 13

Thank you

@ziobrandoalberto.brandolini@avanscoperta.it

giovedì 23 maggio 13

Recommended