DDD session BrownBagLunch (FR)
-
Upload
martraire-cyrille -
Category
Technology
-
view
170 -
download
4
description
Transcript of DDD session BrownBagLunch (FR)
![Page 1: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/1.jpg)
Overview
Domain-Driven Design+ Hands-On Workshop
Cyrille Martraire@cyriux
![Page 2: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/2.jpg)
Passionate developer
PARISSince 1999
@cyriux
![Page 3: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/3.jpg)
Paris Software Craftsmanship Community
http://www.meetup.com/paris-software-craftsmanship/
![Page 4: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/4.jpg)
TDDBDDDDDLegacy
![Page 5: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/5.jpg)
![Page 6: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/6.jpg)
Executive Summary
Domain-Driven Design :
• Priorité au domaine, devant la technique• Parler le langage du métier, pour tout le
monde, dans le code et dans les tests• Le code est le modèle (et vice-versa)• Mon arme secrète sur mes projets depuis
2005
![Page 7: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/7.jpg)
![Page 8: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/8.jpg)
![Page 9: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/9.jpg)
h"p://www.virtual-‐genius.com/blog/post/Domain-‐Driven-‐Design-‐Immersion-‐Course-‐e28093-‐Part-‐5.aspx
![Page 10: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/10.jpg)
Seniors Developers
h"p://www.thisisio.ie/blog/arDcle/149/hiring_senior_developer
![Page 11: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/11.jpg)
I. Putting the model to work
II. Building blocks (Tactical DDD)
III. Refactoring toward deeper insight
IV. Strategic DDD
![Page 12: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/12.jpg)
I. Putting the model to work
II. Building blocks (Tactical DDD)
III. Refactoring toward deeper insight
IV. Strategic DDD
![Page 13: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/13.jpg)
DDD +BDD +TDD = VERY GOOD FRIENDS!
h"p://www.alicia-‐logic.com/capspages/caps_viewall.asp?Dtleid=16
![Page 14: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/14.jpg)
Souvent DénaturéSans outillage
spécifique
CQRS: + populaire
Très respecté
![Page 15: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/15.jpg)
UNE CURIOSITÉ SINCÈRE POUR LE MÉTIER
Au commencement :
h"p://jnchaintreuil.com/et-‐si-‐le-‐futur-‐appartenait-‐aux-‐curieux/
![Page 16: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/16.jpg)
Investir dans la connaissance métier
Mini-‐training 30mn bi-‐hebdo
h"p://www.femmeactuelle.fr/jardin/jardinage-‐les-‐conseils/arroser-‐son-‐jardin-‐pendant-‐les-‐vacances-‐00873
![Page 17: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/17.jpg)
Domain Expert
h"p://bakchich-‐old.staDc.ddz.fr/IMG/jpg_expert-‐2.jpg
![Page 18: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/18.jpg)
Le langage compte!
• La modélisaDon commence avec le langage
• A"enDons aux « synonymes » et aux mots centraux du méDer
• Poser des bonnes (meilleures) quesDons
h"p://journalism.about.com/od/reporDng/tp/Finding-‐And-‐Developing-‐Ideas-‐For-‐News-‐Stories-‐And-‐ArDcles.htm
![Page 19: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/19.jpg)
Ubiquitous Language
• Nommer•Facile à chercher•Prononçables•Sans abréviation
• Définir•Définition partagée•Comprendre, pas juste un vocabulaire
h"p://scalin.fr/rubrique-‐technique/glossaire
![Page 20: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/20.jpg)
Invariants
« Le marché des instruments dérivés est à somme nulle »
Σ Cash Flows (toutes les contreparDes) = 0
![Page 21: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/21.jpg)
Bounded Contexts
Il n’est pas possible de convenir du sens précis des mots uDlisés par un grand nombre de personnes.
Il faut accepter ce fait, et donc définir dans quel contexte un langage est clairement défini sans ambiguité.
![Page 22: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/22.jpg)
Bounded Contexts
→ Context Game
![Page 23: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/23.jpg)
En gros
• DDD : façon d’aborder les problèmes + soluDons
•Focus sur le méDer
•Focus sur un langage méDer omniprésent•Focus sur le core domain
![Page 24: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/24.jpg)
![Page 25: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/25.jpg)
In practice (code)
25
![Page 26: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/26.jpg)
Modeling
26
![Page 27: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/27.jpg)
*NOT* UML/MDA!
h"p://depinfo.u-‐cergy.fr/projets/close2u/fr/tag/uml/
![Page 28: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/28.jpg)
No Translation: Code == Model
• Ubiquitous Langage dans le code• Noms de classes & interfaces
• Noms de méthodes
• Code lisible en prose autant que possible
•≥ 80% noms de classes & méthodes lisibles par le méDer
![Page 29: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/29.jpg)
Signal to Noise ratio
http://www.flickr.com/photos/28471130@N07/2666802097
![Page 30: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/30.jpg)
Signal to Noise Ratio
• SNR ≥ 80 %
• Signal: CashFlow, CashFlowSequence, CashFlowEngine, FinancialProduct, BankHolidays, ReferenceData
• Noise: CashFlowBuilder, CompositeEngine, ProductFactory, BankHolidaysDecorator, SMTPImpl
![Page 31: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/31.jpg)
Tactical Patterns(to help write code with more signal less noise)
31
![Page 32: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/32.jpg)
null
Code concentré en métier
• 100% méDer (ou presque)
• No framework polluDon• Spring, Hibernate, logger
• No javax.*
• No SQL
• Only
h"p://code.google.com/p/guava-‐libraries/
Dans le modèle de domaine
![Page 33: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/33.jpg)
[Object Calisthenics]
1. Wrap all primitives and strings2. Use only one dot per line3. Don’t abbreviate4. Keep all classes small5. Don’t use any classes with more than
two instance variables6. Use first-class collections7. Don’t use any getters/setters/
properties
![Page 34: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/34.jpg)
3 kinds of classes:Value Objects
EntitiesServices
34
![Page 35: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/35.jpg)
Value Object• No parDcular idenDty, equality by value
• Immutable• Constructor / StaDc Creator / Factory method
• FP-‐Style
• Side-‐effect-‐freeMon choix par défaut, sauf si vraiment pas possible !
![Page 36: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/36.jpg)
Equality by value
Value Object
![Page 37: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/37.jpg)
« DayShiX by -‐2 WORKING days »
No ge^er/se^er
Immutable
Enum
Behavior!
![Page 38: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/38.jpg)
• Fowler pa"erns: QuanDty, Range, Money...
• Functional programming style• Immutable, clone to mutate• Capture values (snapshot) • History object of every version
• Builder to help creation• Common example:• String & StringBuilder
Value Object
![Page 39: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/39.jpg)
Défini par une idenDté arbitraire
NoDon de conDnuité dans le temps
Entities
![Page 40: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/40.jpg)
Une collecDon d’objets liés qui partagent une cohérence ensembles, avec une enDté racine pour l’idenDté : Aggregate Root
Aggregates
h"p://www.boitearece"es.com/fruits_legumes/raisin-‐text.htm
![Page 41: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/41.jpg)
Ni une valeur ni une enDté
Services
h"p://www.andeka.co.cc/2011/07/postbox-‐251.html
![Page 42: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/42.jpg)
Persistence Ignorance
• You can defer decisions about persistence (and UI) for a long Dme
• Your domain must NOT care!
![Page 43: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/43.jpg)
Un service, la facade coté méDer d’un stockage
Sans jamais parler de base de données.
Repository
h"p://www.andeka.co.cc/2011/07/postbox-‐251.html
![Page 44: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/44.jpg)
Repository
h"p://www.andeka.co.cc/2011/07/postbox-‐251.html
Interface
DAO
![Page 45: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/45.jpg)
A predicate to filter something
Specification
boolean isSatisfied(...);
![Page 46: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/46.jpg)
Hexagonal Architecture
h"p://pragprog.com/magazines/2009-‐12/going-‐naked
Depends on nothing
![Page 47: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/47.jpg)
Now for some practice
Context Game
![Page 48: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/48.jpg)
Context GameDDD
![Page 49: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/49.jpg)
Context Game[préchauffe]
“What's your ideal <kitten>?”
•Grand-mère: doux, affectueux•Agent d’entretien: propre, ne perd pas de poils
![Page 50: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/50.jpg)
Context Game
“What's your ideal <customer>?”•Sales:•Shipping:•Marketing:•Billing: •Support: •Billed customer assistance:
![Page 51: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/51.jpg)
Context Game
“What's your ideal <customer>?”•Sales: Impulse buyer, lots of money, lots of needs•Shipping: Lives nearby, always at home•Marketing: Very gullible•Billing: Very solvable, pays in advance cash•Support: Very clever, never needs any help•Billed customer assistance: Very stupid, can’t manage to do anything without help
![Page 52: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/52.jpg)
Different perspectives
MY customer is not the same as YOUR customer
![Page 53: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/53.jpg)
“Describe what you need to represent customer in your context”
•data•queries•stats•behaviors
Let’s analyze further
![Page 54: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/54.jpg)
“At Amazon, what a book is for you?” •Catalog: Picture, title, authors, rating, format (ebook or paper), category•Recommandation: List of books often bought together with it•Shipping: Dimensions, weight, international restrictions due to content•Shopping cart: Price, discount eligible•Customer review: List of (rating, review, review rating) •Book Search: title, isbn, authors•Search Inside!: full-text content, copyright-dealing policy
![Page 55: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/55.jpg)
Conflicting aspects suggest several contexts
“I don’t need all these data to do that, I just need these 3 fields”
![Page 56: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/56.jpg)
Several contexts = opportunities
Simplify: Isolated bounded contexts Vs Union of all in one universal do-it-all object
Partitioning: Full-Stack Autonomous Components (screen mashup) Vs. Bounded Contexts in domain layer only; CQRS
Partitioning: teams, work in parallel; scalability; no cross context Tx, EC
![Page 57: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/57.jpg)
![Page 58: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/58.jpg)
![Page 59: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/59.jpg)
![Page 60: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/60.jpg)
![Page 61: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/61.jpg)
Merci !
h"p://cathy313.centerblog.net/539-‐bisounours
![Page 62: DDD session BrownBagLunch (FR)](https://reader031.fdocuments.in/reader031/viewer/2022020122/54977898ac7959412e8b5333/html5/thumbnails/62.jpg)
Merci!