SlideShare une entreprise Scribd logo
1  sur  51
Domain Driven Design
Primer
The
Communication
Chasm
Reduce Verbal Friction
DDD and it’s components
Ubiquitous Language
Sounds Easy
It’s not
Technical Terms
class Customer {
public string Cust_Name {…}
}
class CustomerFactory {
…
}
Not Just Class Names
Industry vs Business
Nomenclatures
class GobbleGobble {
…
}
// or
class Turkey {
…
}
Fluency
invoice.ChangeShipDateTo
(newShipDate)
Code Impact
Aggregate Roots
Purchaser
Invoice
Ship To
Address Items
Product Discount
Code
Tax
Code
Billing
Address
Many per Application
Overlap
Invoice
vs
Statement.Invoice
Clarity > Reuse
Context is King
Encapsulation
class Invoice {
public List<InvoiceItem> Items
{ get; set; }
}
invoice.Items.Add
(new InvoiceItem);
class Invoice {
private List<InvoiceItem> _items;
public IEnumerable<InvoiceItem> Items
{ get {return _items;}}
public void AddItem(InvoiceItem item) {
_items.Add(item);
//change invoice total
//change invoice tax totals
//change invoice item count
}
}
class Invoice {
public void ChangeShippingAddressTo(
ShippingAddress newAddress) {
//change address
//add change fee
//etc.
}
}
invoice.ShippingAddress.XXX =
“blah”;
var xyz =
invoice.ShippingAddress.XXX;
Data Access
UI
Service Layer
Domain Model
Data Access
Only via Aggregate Roots
Load aggregate root
Modify values
Persist aggregate root
But now we’re loading things
we might not need/use…
Use an ORM
Lazy Loading
DDD anti-patterns
Anemic Domain Model
Default constructors
1 Repository class
:
1 Domain class
Domain model in the UI
Auto-mapping
from
UI -> Domain model
Public property setters
What will happen
when you try DDD?
You’ll have to talk to the
business more
The business will talk to you
just like your code reads
You will struggle
to give up the
“One model to rule them all”
Large, complex systems
will seem simpler
Find it hard to keep the
model out of the UI
Have difficulties when
reading data for display
Erroneously try to use DDD
everywhere
donald.belcham@igloocoder.com
@dbelcham
www.igloocoder.com

Contenu connexe

Similaire à Domain Driven Design Primer

3.2. Process Order Info (Change the name ComponentModule .docx
3.2. Process Order Info (Change the name ComponentModule .docx3.2. Process Order Info (Change the name ComponentModule .docx
3.2. Process Order Info (Change the name ComponentModule .docx
gilbertkpeters11344
 
C:\Fakepath\Combating Software Entropy 2
C:\Fakepath\Combating Software Entropy 2C:\Fakepath\Combating Software Entropy 2
C:\Fakepath\Combating Software Entropy 2
Hammad Rajjoub
 
Programming services-slides
Programming services-slidesProgramming services-slides
Programming services-slides
MasterCode.vn
 

Similaire à Domain Driven Design Primer (20)

JDD 2016 - Jakub Kubrynski - Jpa - beyond copy-paste
JDD 2016 - Jakub Kubrynski - Jpa - beyond copy-pasteJDD 2016 - Jakub Kubrynski - Jpa - beyond copy-paste
JDD 2016 - Jakub Kubrynski - Jpa - beyond copy-paste
 
Rich Object Models & Angular.js
Rich Object Models & Angular.jsRich Object Models & Angular.js
Rich Object Models & Angular.js
 
Dependency injection in CakePHP
Dependency injection in CakePHPDependency injection in CakePHP
Dependency injection in CakePHP
 
JPA - Beyond copy-paste
JPA - Beyond copy-pasteJPA - Beyond copy-paste
JPA - Beyond copy-paste
 
The Science of Submissions Part IB - How to handle grouping and worksharing i...
The Science of Submissions Part IB - How to handle grouping and worksharing i...The Science of Submissions Part IB - How to handle grouping and worksharing i...
The Science of Submissions Part IB - How to handle grouping and worksharing i...
 
Design patterns for fun and profit
Design patterns for fun and profitDesign patterns for fun and profit
Design patterns for fun and profit
 
Sylius and Api Platform The story of integration
Sylius and Api Platform The story of integrationSylius and Api Platform The story of integration
Sylius and Api Platform The story of integration
 
3.2. Process Order Info (Change the name ComponentModule .docx
3.2. Process Order Info (Change the name ComponentModule .docx3.2. Process Order Info (Change the name ComponentModule .docx
3.2. Process Order Info (Change the name ComponentModule .docx
 
C:\Fakepath\Combating Software Entropy 2
C:\Fakepath\Combating Software Entropy 2C:\Fakepath\Combating Software Entropy 2
C:\Fakepath\Combating Software Entropy 2
 
C:\Fakepath\Combating Software Entropy 2
C:\Fakepath\Combating Software Entropy 2C:\Fakepath\Combating Software Entropy 2
C:\Fakepath\Combating Software Entropy 2
 
Combatendo code smells em Java
Combatendo code smells em Java Combatendo code smells em Java
Combatendo code smells em Java
 
Capstone ms2
Capstone ms2Capstone ms2
Capstone ms2
 
Fb50 posting gl document
Fb50 posting gl documentFb50 posting gl document
Fb50 posting gl document
 
Soa Symposium Expressing Service Capabilities Uniformly 2009 10 14 Bc
Soa Symposium   Expressing Service Capabilities Uniformly 2009 10 14 BcSoa Symposium   Expressing Service Capabilities Uniformly 2009 10 14 Bc
Soa Symposium Expressing Service Capabilities Uniformly 2009 10 14 Bc
 
Purchase contract
Purchase contractPurchase contract
Purchase contract
 
Greg Demo Slides
Greg Demo SlidesGreg Demo Slides
Greg Demo Slides
 
Chap10
Chap10Chap10
Chap10
 
Introduction to Domain driven design (LaravelBA #5)
Introduction to Domain driven design (LaravelBA #5)Introduction to Domain driven design (LaravelBA #5)
Introduction to Domain driven design (LaravelBA #5)
 
Programming services-slides
Programming services-slidesProgramming services-slides
Programming services-slides
 
DDD meets CQRS and event sourcing
DDD meets CQRS and event sourcingDDD meets CQRS and event sourcing
DDD meets CQRS and event sourcing
 

Plus de Donald Belcham

Design patterns you didn't know about
Design patterns you didn't know aboutDesign patterns you didn't know about
Design patterns you didn't know about
Donald Belcham
 
Programming Closer to the Iron
Programming Closer to the IronProgramming Closer to the Iron
Programming Closer to the Iron
Donald Belcham
 
Taming Brownfield Codebases with AOP
Taming Brownfield Codebases with AOPTaming Brownfield Codebases with AOP
Taming Brownfield Codebases with AOP
Donald Belcham
 
The Dark Side of Code Metrics
The Dark Side of Code MetricsThe Dark Side of Code Metrics
The Dark Side of Code Metrics
Donald Belcham
 

Plus de Donald Belcham (19)

Introduction to Messaging
Introduction to MessagingIntroduction to Messaging
Introduction to Messaging
 
Advanced messaging patterns
Advanced messaging patternsAdvanced messaging patterns
Advanced messaging patterns
 
Microservices: The Nitty Gritty
Microservices: The Nitty GrittyMicroservices: The Nitty Gritty
Microservices: The Nitty Gritty
 
Microservices: A Gentle Introduction
Microservices: A Gentle IntroductionMicroservices: A Gentle Introduction
Microservices: A Gentle Introduction
 
Intro To AOP
Intro To AOPIntro To AOP
Intro To AOP
 
Source Control Abominations
Source Control AbominationsSource Control Abominations
Source Control Abominations
 
Is There Room for Craftsmanship in Software Development
Is There Room for Craftsmanship in Software DevelopmentIs There Room for Craftsmanship in Software Development
Is There Room for Craftsmanship in Software Development
 
Reducing External Risk
Reducing External RiskReducing External Risk
Reducing External Risk
 
Performance Tuning in the Trenches
Performance Tuning in the TrenchesPerformance Tuning in the Trenches
Performance Tuning in the Trenches
 
Reliability and Resilience
Reliability and ResilienceReliability and Resilience
Reliability and Resilience
 
Reliability and Reslience
Reliability and ReslienceReliability and Reslience
Reliability and Reslience
 
Introduction To AOP
Introduction To AOPIntroduction To AOP
Introduction To AOP
 
Design patterns you didn't know about
Design patterns you didn't know aboutDesign patterns you didn't know about
Design patterns you didn't know about
 
Programming Closer to the Iron
Programming Closer to the IronProgramming Closer to the Iron
Programming Closer to the Iron
 
Taming Brownfield Codebases with AOP
Taming Brownfield Codebases with AOPTaming Brownfield Codebases with AOP
Taming Brownfield Codebases with AOP
 
Hacking Hardware
Hacking HardwareHacking Hardware
Hacking Hardware
 
Advanced AOP
Advanced AOPAdvanced AOP
Advanced AOP
 
The Dark Side of Code Metrics
The Dark Side of Code MetricsThe Dark Side of Code Metrics
The Dark Side of Code Metrics
 
Continuous Deployment
Continuous DeploymentContinuous Deployment
Continuous Deployment
 

Dernier

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Dernier (20)

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 

Domain Driven Design Primer

Notes de l'éditeur

  1. Database terminology or naming creeps into the code
  2. Design pattern terminology creeps into the code which is not how the business talks
  3. Properties, methods, events,enums, etc should all use the terms used by the business users
  4. Industry may seem more “proper” or “correct” but if the business uses the term so should you. One exception is when you are building an app to be used by multiple businesses in the same industry.
  5. Making your code read like the business speaks
  6. Database terminology or naming creeps into the code
  7. Business usually talks in focused areas. i.e. Inventory or Invoicing or Accounting.
  8. Business usually talks in focused areas. i.e. Inventory or Invoicing or Accounting.
  9. Except in the smallest of apps
  10. Aggregate roots will overlap with each other. This is fine. Remember to work within the context of that aggregate root though.
  11. Invoice might be detailed as outlined in our previous example. Statement.Invoice might just be a summary of that information.
  12. Model clarity is significantly more valuable than code reuse in almost all cases. Interface Segregation Principle is very important here.
  13. The context that you are working in is more important than the overriding concept
  14. When we take a business action it’s very common for many things to need to happen. Encapsulate those into methods on the Aggregate root
  15. Law of Demeter. You can pick your nose and you can pick your friends. You can’t pick your friend’s nose. You can, however, look at your friend’s nose.
  16. Service and Data Access layers know about Domain Model, but not the other way around
  17. The only items that should be passed to the data access layer are the aggregate root objects.
  18. The pattern of work that results from only doing data access with the aggregate root.
  19. Working with aggregate roots only can mean you are going to load data into objects in the tree that you may not use.
  20. Without an ORM the aggregate root DAL approach becomes very painful
  21. Leverage the functionality of the ORM. Load data only when you need it.
  22. A domain model that is only properties. We want our models to be rich, or Rubenesque; properties, methods and events will exist.
  23. If domain objects only use default constructors something is missing. Usually when you create a “new” instance of an object there will be minimum requirements for that object to be valid.
  24. 1 repository to 1 aggregate root. All data access happens via aggregate roots.
  25. Domain model maps to the business functionality not to how it displays
  26. Auto-mapping from domain to UI is a great thing. When pulling data from the UI we want to apply it to the domain model via methods exposed on the aggregate root. Auto-mapping can’t do this. It can only do property to property
  27. Publically exposing property setters can indicate that the model is anemic.
  28. Changing your thought pattern to having overlapping aggregates and multiple classes representing the same data tables is difficult.
  29. Sometimes it seems like silly extra work to keep a UI model and a domain model separate. Sometimes this can indicate that all you’re building is forms-over-data with no business richness.
  30. DDD is great for the C, U and D parts of CRUD but it isn’t a great solution for the R portion. Separating how you read data for display on the screen makes the retrieval of the data much easier. Look into CQRS which separates these two concepts nicely.
  31. Knowing when there isn’t enough complexity to warrant DDD is just as important as knowing how to do DDD