DDD session BrownBagLunch (FR)
-
Upload
martraire-cyrille -
Category
Technology
-
view
170 -
download
4
description
Transcript of DDD session BrownBagLunch (FR)
Overview
Domain-Driven Design+ Hands-On Workshop
Cyrille Martraire@cyriux
Passionate developer
PARISSince 1999
@cyriux
Paris Software Craftsmanship Community
http://www.meetup.com/paris-software-craftsmanship/
TDDBDDDDDLegacy
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
h"p://www.virtual-‐genius.com/blog/post/Domain-‐Driven-‐Design-‐Immersion-‐Course-‐e28093-‐Part-‐5.aspx
Seniors Developers
h"p://www.thisisio.ie/blog/arDcle/149/hiring_senior_developer
I. Putting the model to work
II. Building blocks (Tactical DDD)
III. Refactoring toward deeper insight
IV. Strategic DDD
I. Putting the model to work
II. Building blocks (Tactical DDD)
III. Refactoring toward deeper insight
IV. Strategic DDD
DDD +BDD +TDD = VERY GOOD FRIENDS!
h"p://www.alicia-‐logic.com/capspages/caps_viewall.asp?Dtleid=16
Souvent DénaturéSans outillage
spécifique
CQRS: + populaire
Très respecté
UNE CURIOSITÉ SINCÈRE POUR LE MÉTIER
Au commencement :
h"p://jnchaintreuil.com/et-‐si-‐le-‐futur-‐appartenait-‐aux-‐curieux/
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
Domain Expert
h"p://bakchich-‐old.staDc.ddz.fr/IMG/jpg_expert-‐2.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
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
Invariants
« Le marché des instruments dérivés est à somme nulle »
Σ Cash Flows (toutes les contreparDes) = 0
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é.
Bounded Contexts
→ Context Game
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
In practice (code)
25
Modeling
26
*NOT* UML/MDA!
h"p://depinfo.u-‐cergy.fr/projets/close2u/fr/tag/uml/
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
Signal to Noise ratio
http://www.flickr.com/photos/28471130@N07/2666802097
Signal to Noise Ratio
• SNR ≥ 80 %
• Signal: CashFlow, CashFlowSequence, CashFlowEngine, FinancialProduct, BankHolidays, ReferenceData
• Noise: CashFlowBuilder, CompositeEngine, ProductFactory, BankHolidaysDecorator, SMTPImpl
Tactical Patterns(to help write code with more signal less noise)
31
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
[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
3 kinds of classes:Value Objects
EntitiesServices
34
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 !
Equality by value
Value Object
« DayShiX by -‐2 WORKING days »
No ge^er/se^er
Immutable
Enum
Behavior!
• 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
Défini par une idenDté arbitraire
NoDon de conDnuité dans le temps
Entities
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
Ni une valeur ni une enDté
Services
h"p://www.andeka.co.cc/2011/07/postbox-‐251.html
Persistence Ignorance
• You can defer decisions about persistence (and UI) for a long Dme
• Your domain must NOT care!
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
Repository
h"p://www.andeka.co.cc/2011/07/postbox-‐251.html
Interface
DAO
A predicate to filter something
Specification
boolean isSatisfied(...);
Hexagonal Architecture
h"p://pragprog.com/magazines/2009-‐12/going-‐naked
Depends on nothing
Now for some practice
Context Game
Context GameDDD
Context Game[préchauffe]
“What's your ideal <kitten>?”
•Grand-mère: doux, affectueux•Agent d’entretien: propre, ne perd pas de poils
Context Game
“What's your ideal <customer>?”•Sales:•Shipping:•Marketing:•Billing: •Support: •Billed customer assistance:
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
Different perspectives
MY customer is not the same as YOUR customer
“Describe what you need to represent customer in your context”
•data•queries•stats•behaviors
Let’s analyze further
“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
Conflicting aspects suggest several contexts
“I don’t need all these data to do that, I just need these 3 fields”
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
Merci !
h"p://cathy313.centerblog.net/539-‐bisounours
Merci!