ricette veloci per domain-driven design by alberto brandolini
DESCRIPTION
Come modelliamo gli aggregati? Qual è la strategia migliore per implementare un dominio complesso. Ci sono pattern ricorrenti nell’implementazione di applicazioni in DDD? Per quale motivo dovrei utilizzare CQRS? E se i Maya avessero avuto ragione e non ce ne fossimo accorti? Queste ed altre domande ancora…TRANSCRIPT
Ricette veloci per Domain-Driven Design
dal menù di @ziobrando
venerdì 22 marzo 13
About meIn the IT field since ZX SpectrumGenerally in large scale projects (I might be biased)
Strategic IT ConsultantTrainer (Avanscoperta & Skills Matter)Technical Writer
Blogger: http://ziobrando.blogspot.comTwitter: @ziobrando
My e-mail: [email protected]
venerdì 22 marzo 13
About me
Mi piace risolvere problemiO scrivere software che li risolva
Blogger: http://ziobrando.blogspot.comTwitter: @ziobrando
My e-mail: [email protected]
venerdì 22 marzo 13
About meIn the IT field since ZX SpectrumGenerally in large scale projects (I might be biased)
Strategic IT ConsultantTrainer (Avanscoperta & Skills Matter)Technical Writer
Blogger: http://ziobrando.blogspot.comTwitter: @ziobrando
My e-mail: [email protected]
venerdì 22 marzo 13
Aggregates
It is difficult to guarantee the consistency of changes to objects in a model with complex associations. Invariants need to be maintained that apply to closely related groups of objects, not just discrete objects.
An AGGREGATE is a cluster of associated objects that we treat as a unit for the purpose of data changes.
venerdì 22 marzo 13
...quale miglior aggregato?
venerdì 22 marzo 13
Customer!
Customer
venerdì 22 marzo 13
Customer!
<<Entity>>Customer
venerdì 22 marzo 13
Customer!<<Aggregate Root>>
<<Entity>>Customer
venerdì 22 marzo 13
Customer!<<Aggregate Root>>
<<Entity>>Customer
nomecognome
venerdì 22 marzo 13
Customer!<<Aggregate Root>>
<<Entity>>Customer
nomecognomeusernameemailAddress
venerdì 22 marzo 13
Customer!<<Aggregate Root>>
<<Entity>>Customer
nomecognomeusernameemailAddressaddresscountrylanguage
venerdì 22 marzo 13
Domande?
venerdì 22 marzo 13
Domande?-Persistenza?
venerdì 22 marzo 13
Domande?-Persistenza?
- Fa tutto lui! :-)
venerdì 22 marzo 13
Domande?-Persistenza?
- Fa tutto lui! :-)
-Come gestisco address?
venerdì 22 marzo 13
Domande?-Persistenza?
- Fa tutto lui! :-)
-Come gestisco address?
-Dove tengo la password?
venerdì 22 marzo 13
Domande?-Persistenza?
- Fa tutto lui! :-)
-Come gestisco address?
-Dove tengo la password?
venerdì 22 marzo 13
Domande?-Persistenza?
- Fa tutto lui! :-)
-Come gestisco address?
-Dove tengo la password?
venerdì 22 marzo 13
È un mappazzone!
venerdì 22 marzo 13
Dov’è il comportamento?
venerdì 22 marzo 13
Riproviamo
venerdì 22 marzo 13
Trucco N°1-
CQRSCommand/Query Responsibility Segregation
venerdì 22 marzo 13
?
! Architettura ottimizzata per i comandi
Architettura ottimizzata per le letture
venerdì 22 marzo 13
Aggregate
Aggregate
Command
Command
Event
Event
Event
EventEvent
EventEventEventEvent store
Domain Model
Projection
Projection
Read Model
DTO
DTO
Pre
sen
tati
on
UI
UI
UI
UI
venerdì 22 marzo 13
Non solo velocitàvenerdì 22 marzo 13
Non parleremo di questo...
venerdì 22 marzo 13
Conceptual CQRS
Command
User
issues
influences
External information
influencesRead Model
Domain Modelto
Event
raises
Projection
notified to
updates
Warning! non è architettura...venerdì 22 marzo 13
Qui decide l’utenteCommand
User
issues
influences
External information
influencesRead Model
venerdì 22 marzo 13
Quali informazioni
venerdì 22 marzo 13
User Steps- L’utente decide quali comandi
invocare sul sistema sulla base delle informazioni derivanti dalla sua esperienza, e da quanto reso disponibile dall’applicazione
venerdì 22 marzo 13
Examples?
-Timesheet entry
venerdì 22 marzo 13
Conceptual CQRS
Command
User
issues
influences
External information
influencesRead Model
Domain Modelto
Event
raises
Projection
notified to
updates
venerdì 22 marzo 13
Vi ho tolto il DB!
venerdì 22 marzo 13
Piangere non servirà a nulla...
venerdì 22 marzo 13
Conceptual CQRS
Command
User
issues
influences
External information
influencesRead Model
Domain Modelto
Event
raises
Projection
notified to
updates
venerdì 22 marzo 13
Aggregates
It is difficult to guarantee the consistency of changes to objects in a model with complex associations. Invariants need to be maintained that apply to closely related groups of objects, not just discrete objects.
An AGGREGATE is a cluster of associated objects that we treat as a unit for the purpose of data changes.
venerdì 22 marzo 13
Aggregate History
venerdì 22 marzo 13
Aggregate History- Propagazione
venerdì 22 marzo 13
Aggregate History- Propagazione
- 2004 una generica “comunicazione asincrona”
venerdì 22 marzo 13
Aggregate History- Propagazione
- 2004 una generica “comunicazione asincrona”
- 2010 ... Domain Events
venerdì 22 marzo 13
Aggregate History- Propagazione
- 2004 una generica “comunicazione asincrona”
- 2010 ... Domain Events
- Struttura interna:
venerdì 22 marzo 13
Aggregate History- Propagazione
- 2004 una generica “comunicazione asincrona”
- 2010 ... Domain Events
- Struttura interna:
- 2004: “Don’t fight your frameworks”
venerdì 22 marzo 13
Aggregate History- Propagazione
- 2004 una generica “comunicazione asincrona”
- 2010 ... Domain Events
- Struttura interna:
- 2004: “Don’t fight your frameworks”
- ORM / NoSQL / Event Sourcing / Functional...
venerdì 22 marzo 13
Domain Model
Command Domain Modelto
Event
raises
venerdì 22 marzo 13
Domain Model
-Qui è dove è il sistema a prendere le decisioni.
venerdì 22 marzo 13
I dati non sono tutti igualiIl sistema prenderà una decisone basandosi su questi dati
..l’utente si baserà su questi, ed altro...
venerdì 22 marzo 13
Come lo preparo?
venerdì 22 marzo 13
Domain Model
Command Domain Modelto
Event
raises
venerdì 22 marzo 13
Outside in
venerdì 22 marzo 13
Non ci guardo dentro...
venerdì 22 marzo 13
...
venerdì 22 marzo 13
...
...ma se devo prendere le informazioni da un’altro
aggregato?
venerdì 22 marzo 13
venerdì 22 marzo 13
Quando eri bambino aprivi i
cassetti in camera di mamma di tuoi amici
per annusare mutande?
venerdì 22 marzo 13
Tell don’t ask
venerdì 22 marzo 13
Ai fornelli
venerdì 22 marzo 13
Uova al tegame
In presenza di sufficiente calore, l’albume coagula più rapidamente del tuorlo. che è più digeribile in forma liquida.
Un UOVO AL TEGAME si ottiene ponendo l’uovo sgusciato su una superficie piana, calda e non aderente, per un tempo sufficientemente lungo da consentire la coagulazione dell’albume, preservando il tuorlo.
venerdì 22 marzo 13
“Metti un po’ di burro in padella,
apri l’uovo e cuoci”
venerdì 22 marzo 13
Non avete bisogno di lui
venerdì 22 marzo 13
Basta lei
venerdì 22 marzo 13
È un uovo!venerdì 22 marzo 13
Invariant
An INVARIANT is a condition that can relied upon to be true during the execution of a program.
venerdì 22 marzo 13
Invarianti?
Totale = Somma(prezzoUnitario*quantità)
venerdì 22 marzo 13
Comandi?
AddItem
Cartto
ItemAddedToCartraises
RemoveItem to ItemRemovedFromCartraises
CreateEmptyto
CartCreatedraises
Totale = Somma(prezzoUnitario*quantità)
venerdì 22 marzo 13
Problema
- Il prezzo degli articoli può variare.
venerdì 22 marzo 13
Quindi?
venerdì 22 marzo 13
Quindi?
No, è che ha detto [nome di uno troppo importante per parlare con voi] che il prezzo
può cambiare...
venerdì 22 marzo 13
Quindi?
No, è che ha detto [nome di uno troppo importante per parlare con voi] che il prezzo
può cambiare...
...e va implementata per
dopodomani.
venerdì 22 marzo 13
Quindi?
No, è che ha detto [nome di uno troppo importante per parlare con voi] che il prezzo
può cambiare...
...e va implementata per
dopodomani.
Doveva già essere così.
venerdì 22 marzo 13
Sòla...
venerdì 22 marzo 13
Quindi?
venerdì 22 marzo 13
Quindi?
Puoi farmi un esempio?
venerdì 22 marzo 13
Esempio- Given item stormtrooper clothing is
priced €500 each
- And customer ziobrando added 10 of stormtrooper clothing to cart
- When price for stormtrooper clothing is updated to €750 each
- Then ???
venerdì 22 marzo 13
Quindi?
venerdì 22 marzo 13
Quindi?
...?
venerdì 22 marzo 13
Ma anche...
venerdì 22 marzo 13
Ma anche...Il
comportamento dell’utente cambia se la variazione di prezzo è favorevole o sfavorevole: possiamo
applicare immediatamente gli sconti, e bloccare i rincari per
un giorno.
venerdì 22 marzo 13
Ma anche...Il
comportamento dell’utente cambia se la variazione di prezzo è favorevole o sfavorevole: possiamo
applicare immediatamente gli sconti, e bloccare i rincari per
un giorno....ma solo per alcuni articoli
venerdì 22 marzo 13
Che rumore sentite?
venerdì 22 marzo 13
© Alberto Brandolini 2009
E’ necessario un processo di sviluppo agile, che perme4a di
raccogliere il feedback di uten) e domain experts, in iterazioni brevi.
collaborazione creativa venerdì 22 marzo 13
© Alberto Brandolini 2009
gli esperti ci aiutano a capire
e noi aiutiamo loro
venerdì 22 marzo 13
Bello. Ma oggi...
venerdì 22 marzo 13
Bello. Ma oggi...
...aggiorniamo i prezzi nel carrello
venerdì 22 marzo 13
AddItem
Cart
to
ItemAddedToCartraises
RemoveItem to ItemRemovedFromCartraisesCreateEmpty to
CartCreatedraises
ItemPriceUpdated
<<EventHandler>><<Service>>
…?
to
raises
UpdateItemPriceto
CartPriceUpdated
raises
venerdì 22 marzo 13
Aggregates all’ostrica
venerdì 22 marzo 13
Domain Model
-Qui è dove è il sistema a prendere le decisioni.
- ...sulla basi di quali informazioni?
venerdì 22 marzo 13
I dati non sono tutti igualiIl sistema prenderà una decisone basandosi su questi dati
..l’utente si baserà su questi, ed altro...
venerdì 22 marzo 13
Ho bisogno dell’albume?
venerdì 22 marzo 13
AddItem
Cartto
ItemAddedToCartraises
RemoveItem to ItemRemovedFromCartraises
CreateEmptyto
CartCreatedraises
Solo i dati significativi per l’esecuzione sono modellati
...tutto il contenuto informativo è propagato attraverso gli eventi
venerdì 22 marzo 13
Che ci faccio con l’albume?
venerdì 22 marzo 13
Che ci faccio con l’albume?
venerdì 22 marzo 13
...il read model!
Read Model
Event
Projection
notified to
updates
venerdì 22 marzo 13
I sapori fondamentali
venerdì 22 marzo 13
I sapori fondamentaliDolce
venerdì 22 marzo 13
I sapori fondamentaliDolce
Amaro
venerdì 22 marzo 13
I sapori fondamentaliDolce
Amaro
Salato
venerdì 22 marzo 13
I sapori fondamentaliDolce
Amaro
Salato
Aspro
venerdì 22 marzo 13
I sapori fondamentaliDolce
Amaro
Salato
Aspro
Umami
venerdì 22 marzo 13
Che [*] é umami?
[*] = Colorita espressione regionalevenerdì 22 marzo 13
Che [*] é un invariante?
[*] = Colorita espressione regionalevenerdì 22 marzo 13
3 modelli
-Costruzione
-Esecuzione
-Controllo
venerdì 22 marzo 13
...le invarianti si semplificano
- comportamento differenziato
- condizioni più precise
-possibilità di applicare una differente semantica: es warning vs blocker
- fare le domande giustevenerdì 22 marzo 13
Davvero avete così fretta?
venerdì 22 marzo 13
Comunque...
geteventstore.comvenerdì 22 marzo 13
Per saperne di più... www.avanscoperta.it
Domain-Driven Design Eric Evans
Patterns of Enterprise Application ArchitectureMartin Fowler
Enterprise Integration Patterns
Gregor Hohpe, Bobby Woolf
venerdì 22 marzo 13
http://www.amazon.com/Event-Centric-Simplicity-Addison-Wesley-Signature/dp/0321768221
Per saperne di più... www.avanscoperta.it
http://www.amazon.com/Implementing-Domain-Driven-Design-Vaughn-Vernon/dp/0321834577
Implementing Domain-Driven Design Vaughn Vernon
Event CentricGreg Young
venerdì 22 marzo 13
venerdì 22 marzo 13