SlideShare a Scribd company logo
1 of 35
Domain Driven Design
   Demonstrated
      Alan Christensen
       @christensena




                 Christchurch Code Camp   Feb 18 2012

             1
What is a Domain?




        2
What is a Domain?


• “A sphere of knowledge, influence or
  activity”--Eric Evans




                      2
What is DDD?




     3
What is DDD?
• In order of importance:




                     3
What is DDD?
• In order of importance:
 • Design methodology




                     3
What is DDD?
• In order of importance:
 • Design methodology
 • Architectural style



                     3
What is DDD?
• In order of importance:
 • Design methodology
 • Architectural style
 • Set of software patterns


                    3
What is DDD?
• In order of importance:
 • Design methodology
 • Architectural style
 • Set of software patterns
• “Tackling Complexity in the Heart of
  Software”--DDD book tagline

                     3
Domain Modeling




       4
Domain Modeling
• Understand your domain




                   4
Domain Modeling
• Understand your domain
• Model it in the code to suit the purpose
  and context for which it was intended




                     4
Domain Modeling
• Understand your domain
• Model it in the code to suit the purpose
  and context for which it was intended
• Leave out details and concepts that don’t
  add value



                     4
Domain Modeling
• Understand your domain
• Model it in the code to suit the purpose
  and context for which it was intended
• Leave out details and concepts that don’t
  add value
• Keep refining “refactor to greater insight”
                      4
5
Ubiquitous Language




         6
Ubiquitous Language
• Naming is important!




                    6
Ubiquitous Language
• Naming is important!
• As is a shared understanding and consistent
  use of terms




                     6
Ubiquitous Language
• Naming is important!
• As is a shared understanding and consistent
  use of terms
• The code should use the same terms used
  in documents and discussion




                     6
Ubiquitous Language
• Naming is important!
• As is a shared understanding and consistent
  use of terms
• The code should use the same terms used
  in documents and discussion
• Both domain experts and developers
  contribute to the shared language

                     6
7
7
7
the Welsh reads "I am not in the office at the
moment. Send any work to be translated."
             8
Onion Architecture




        9
Entities




   10
Entities
• Have an identity




                     10
Entities
• Have an identity
• Identity may be determined by a natural or
  assigned key (e.g. Id)




                       10
Entities
• Have an identity
• Identity may be determined by a natural or
  assigned key (e.g. Id)
• Equals implementation to distinguish
  identity normally uses key



                       10
Entities
• Have an identity
• Identity may be determined by a natural or
  assigned key (e.g. Id)
• Equals implementation to distinguish
  identity normally uses key
• Mutable - can be changed
                       10
Value objects




      11
Value objects

• No identity. Can be mixed and matched




                    11
Value objects

• No identity. Can be mixed and matched
• Equals implemented as “all fields/properties
  match”




                     11
Value objects

• No identity. Can be mixed and matched
• Equals implemented as “all fields/properties
  match”
• Immutable - replace instead of change

                     11
Worked example

• What domain should we use?
 • Inventory?
 • Payroll?
 • Share trading?

                   12

More Related Content

What's hot

Domain Driven Design (DDD)
Domain Driven Design (DDD)Domain Driven Design (DDD)
Domain Driven Design (DDD)Tom Kocjan
 
Domain Driven Design(DDD) Presentation
Domain Driven Design(DDD) PresentationDomain Driven Design(DDD) Presentation
Domain Driven Design(DDD) PresentationOğuzhan Soykan
 
Modelling a complex domain with Domain-Driven Design
Modelling a complex domain with Domain-Driven DesignModelling a complex domain with Domain-Driven Design
Modelling a complex domain with Domain-Driven DesignNaeem Sarfraz
 
Domain Driven Design Introduction
Domain Driven Design IntroductionDomain Driven Design Introduction
Domain Driven Design Introductionwojtek_s
 
Domain Driven Design Quickly
Domain Driven Design QuicklyDomain Driven Design Quickly
Domain Driven Design QuicklyMariam Hakobyan
 
Implementing DDD with C#
Implementing DDD with C#Implementing DDD with C#
Implementing DDD with C#Pascal Laurin
 
Domain Driven Design - Strategic Patterns and Microservices
Domain Driven Design - Strategic Patterns and MicroservicesDomain Driven Design - Strategic Patterns and Microservices
Domain Driven Design - Strategic Patterns and MicroservicesRadosław Maziarka
 
How to Implement Domain Driven Design in Real Life SDLC
How to Implement Domain Driven Design  in Real Life SDLCHow to Implement Domain Driven Design  in Real Life SDLC
How to Implement Domain Driven Design in Real Life SDLCAbdul Karim
 
A Practical Guide to Domain Driven Design: Presentation Slides
A Practical Guide to Domain Driven Design: Presentation SlidesA Practical Guide to Domain Driven Design: Presentation Slides
A Practical Guide to Domain Driven Design: Presentation Slidesthinkddd
 
DDD - 1 - A gentle introduction to Domain Driven Design.pdf
DDD - 1 - A gentle introduction to Domain Driven Design.pdfDDD - 1 - A gentle introduction to Domain Driven Design.pdf
DDD - 1 - A gentle introduction to Domain Driven Design.pdfEleonora Ciceri
 
Hexagonal architecture with Spring Boot
Hexagonal architecture with Spring BootHexagonal architecture with Spring Boot
Hexagonal architecture with Spring BootMikalai Alimenkou
 
Applying Domain-Driven Design to craft Rich Domain Models
Applying Domain-Driven Design to craft Rich Domain ModelsApplying Domain-Driven Design to craft Rich Domain Models
Applying Domain-Driven Design to craft Rich Domain ModelsAlexander van Trijffel
 
DDD Strategic Design - Context Maps - Paulo Clavijo - April 2018
DDD Strategic Design - Context Maps - Paulo Clavijo - April 2018DDD Strategic Design - Context Maps - Paulo Clavijo - April 2018
DDD Strategic Design - Context Maps - Paulo Clavijo - April 2018Paulo Clavijo
 

What's hot (20)

Domain Driven Design (DDD)
Domain Driven Design (DDD)Domain Driven Design (DDD)
Domain Driven Design (DDD)
 
Domain Driven Design(DDD) Presentation
Domain Driven Design(DDD) PresentationDomain Driven Design(DDD) Presentation
Domain Driven Design(DDD) Presentation
 
Modelling a complex domain with Domain-Driven Design
Modelling a complex domain with Domain-Driven DesignModelling a complex domain with Domain-Driven Design
Modelling a complex domain with Domain-Driven Design
 
Domain Driven Design Introduction
Domain Driven Design IntroductionDomain Driven Design Introduction
Domain Driven Design Introduction
 
Domain driven design
Domain driven designDomain driven design
Domain driven design
 
Domain Driven Design Quickly
Domain Driven Design QuicklyDomain Driven Design Quickly
Domain Driven Design Quickly
 
Domain Driven Design 101
Domain Driven Design 101Domain Driven Design 101
Domain Driven Design 101
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Implementing DDD with C#
Implementing DDD with C#Implementing DDD with C#
Implementing DDD with C#
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Domain Driven Design - Strategic Patterns and Microservices
Domain Driven Design - Strategic Patterns and MicroservicesDomain Driven Design - Strategic Patterns and Microservices
Domain Driven Design - Strategic Patterns and Microservices
 
Domain driven design
Domain driven designDomain driven design
Domain driven design
 
How to Implement Domain Driven Design in Real Life SDLC
How to Implement Domain Driven Design  in Real Life SDLCHow to Implement Domain Driven Design  in Real Life SDLC
How to Implement Domain Driven Design in Real Life SDLC
 
A Practical Guide to Domain Driven Design: Presentation Slides
A Practical Guide to Domain Driven Design: Presentation SlidesA Practical Guide to Domain Driven Design: Presentation Slides
A Practical Guide to Domain Driven Design: Presentation Slides
 
Domain Driven Design
Domain Driven Design Domain Driven Design
Domain Driven Design
 
DDD - 1 - A gentle introduction to Domain Driven Design.pdf
DDD - 1 - A gentle introduction to Domain Driven Design.pdfDDD - 1 - A gentle introduction to Domain Driven Design.pdf
DDD - 1 - A gentle introduction to Domain Driven Design.pdf
 
Hexagonal architecture with Spring Boot
Hexagonal architecture with Spring BootHexagonal architecture with Spring Boot
Hexagonal architecture with Spring Boot
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Applying Domain-Driven Design to craft Rich Domain Models
Applying Domain-Driven Design to craft Rich Domain ModelsApplying Domain-Driven Design to craft Rich Domain Models
Applying Domain-Driven Design to craft Rich Domain Models
 
DDD Strategic Design - Context Maps - Paulo Clavijo - April 2018
DDD Strategic Design - Context Maps - Paulo Clavijo - April 2018DDD Strategic Design - Context Maps - Paulo Clavijo - April 2018
DDD Strategic Design - Context Maps - Paulo Clavijo - April 2018
 

Similar to Domain Driven Design Demonstrated

ZendCon 2011 UnCon Domain-Driven Design
ZendCon 2011 UnCon Domain-Driven DesignZendCon 2011 UnCon Domain-Driven Design
ZendCon 2011 UnCon Domain-Driven DesignBradley Holt
 
Austin NoSQL 2011-07-06
Austin NoSQL 2011-07-06Austin NoSQL 2011-07-06
Austin NoSQL 2011-07-06jimbojsb
 
Artefacts - Bringing Clarity & Simplicity to Modelling
Artefacts - Bringing Clarity & Simplicity to ModellingArtefacts - Bringing Clarity & Simplicity to Modelling
Artefacts - Bringing Clarity & Simplicity to ModellingJorn Bettin
 
Online TechTalk  "Patterns in Embedded SW Design"
Online TechTalk  "Patterns in Embedded SW Design"Online TechTalk  "Patterns in Embedded SW Design"
Online TechTalk  "Patterns in Embedded SW Design"GlobalLogic Ukraine
 
Schibsted Spain - Day 1 - DDD Course
Schibsted Spain - Day 1 - DDD CourseSchibsted Spain - Day 1 - DDD Course
Schibsted Spain - Day 1 - DDD CourseKevin Mas Ruiz
 
Deployment is the new build
Deployment is the new buildDeployment is the new build
Deployment is the new buildAndrew Phillips
 
Devconf 2011 - PHP - How Yii framework is developed
Devconf 2011 - PHP - How Yii framework is developedDevconf 2011 - PHP - How Yii framework is developed
Devconf 2011 - PHP - How Yii framework is developedAlexander Makarov
 
Intro to Big Data and NoSQL
Intro to Big Data and NoSQLIntro to Big Data and NoSQL
Intro to Big Data and NoSQLDon Demcsak
 
Marco Mancuso - Data Context Interaction
Marco Mancuso - Data Context InteractionMarco Mancuso - Data Context Interaction
Marco Mancuso - Data Context InteractioncosenzaLab
 
Domain Driven Design Ruby Ways - JURNAL 05/10/2017
Domain Driven Design Ruby Ways -  JURNAL 05/10/2017Domain Driven Design Ruby Ways -  JURNAL 05/10/2017
Domain Driven Design Ruby Ways - JURNAL 05/10/2017Jonathan Wylliem
 
Data Modeling for NoSQL
Data Modeling for NoSQLData Modeling for NoSQL
Data Modeling for NoSQLTony Tam
 
The business case for contributing code
The business case for contributing codeThe business case for contributing code
The business case for contributing codeZivtech, LLC
 
Orthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable CodeOrthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable Codersebbe
 
Tooling for the JavaScript Era
Tooling for the JavaScript EraTooling for the JavaScript Era
Tooling for the JavaScript Eramartinlippert
 
Cleaning Code - Tools and Techniques for Large Legacy Projects
Cleaning Code - Tools and Techniques for Large Legacy ProjectsCleaning Code - Tools and Techniques for Large Legacy Projects
Cleaning Code - Tools and Techniques for Large Legacy ProjectsMike Long
 
Website Architecture Presentation from Web Strategy Workshops
Website Architecture Presentation from Web Strategy WorkshopsWebsite Architecture Presentation from Web Strategy Workshops
Website Architecture Presentation from Web Strategy WorkshopsCharles Edmunds
 
Project Tools in Web Development
Project Tools in Web DevelopmentProject Tools in Web Development
Project Tools in Web Developmentkmloomis
 
Domain Driven Design - garajco Education 2017
Domain Driven Design - garajco Education 2017Domain Driven Design - garajco Education 2017
Domain Driven Design - garajco Education 2017Can Pekdemir
 

Similar to Domain Driven Design Demonstrated (20)

ZendCon 2011 UnCon Domain-Driven Design
ZendCon 2011 UnCon Domain-Driven DesignZendCon 2011 UnCon Domain-Driven Design
ZendCon 2011 UnCon Domain-Driven Design
 
Austin NoSQL 2011-07-06
Austin NoSQL 2011-07-06Austin NoSQL 2011-07-06
Austin NoSQL 2011-07-06
 
Artefacts - Bringing Clarity & Simplicity to Modelling
Artefacts - Bringing Clarity & Simplicity to ModellingArtefacts - Bringing Clarity & Simplicity to Modelling
Artefacts - Bringing Clarity & Simplicity to Modelling
 
Online TechTalk  "Patterns in Embedded SW Design"
Online TechTalk  "Patterns in Embedded SW Design"Online TechTalk  "Patterns in Embedded SW Design"
Online TechTalk  "Patterns in Embedded SW Design"
 
Schibsted Spain - Day 1 - DDD Course
Schibsted Spain - Day 1 - DDD CourseSchibsted Spain - Day 1 - DDD Course
Schibsted Spain - Day 1 - DDD Course
 
Deployment is the new build
Deployment is the new buildDeployment is the new build
Deployment is the new build
 
Solr pattern
Solr patternSolr pattern
Solr pattern
 
Zend Di in ZF 2.0
Zend Di in ZF 2.0Zend Di in ZF 2.0
Zend Di in ZF 2.0
 
Devconf 2011 - PHP - How Yii framework is developed
Devconf 2011 - PHP - How Yii framework is developedDevconf 2011 - PHP - How Yii framework is developed
Devconf 2011 - PHP - How Yii framework is developed
 
Intro to Big Data and NoSQL
Intro to Big Data and NoSQLIntro to Big Data and NoSQL
Intro to Big Data and NoSQL
 
Marco Mancuso - Data Context Interaction
Marco Mancuso - Data Context InteractionMarco Mancuso - Data Context Interaction
Marco Mancuso - Data Context Interaction
 
Domain Driven Design Ruby Ways - JURNAL 05/10/2017
Domain Driven Design Ruby Ways -  JURNAL 05/10/2017Domain Driven Design Ruby Ways -  JURNAL 05/10/2017
Domain Driven Design Ruby Ways - JURNAL 05/10/2017
 
Data Modeling for NoSQL
Data Modeling for NoSQLData Modeling for NoSQL
Data Modeling for NoSQL
 
The business case for contributing code
The business case for contributing codeThe business case for contributing code
The business case for contributing code
 
Orthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable CodeOrthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable Code
 
Tooling for the JavaScript Era
Tooling for the JavaScript EraTooling for the JavaScript Era
Tooling for the JavaScript Era
 
Cleaning Code - Tools and Techniques for Large Legacy Projects
Cleaning Code - Tools and Techniques for Large Legacy ProjectsCleaning Code - Tools and Techniques for Large Legacy Projects
Cleaning Code - Tools and Techniques for Large Legacy Projects
 
Website Architecture Presentation from Web Strategy Workshops
Website Architecture Presentation from Web Strategy WorkshopsWebsite Architecture Presentation from Web Strategy Workshops
Website Architecture Presentation from Web Strategy Workshops
 
Project Tools in Web Development
Project Tools in Web DevelopmentProject Tools in Web Development
Project Tools in Web Development
 
Domain Driven Design - garajco Education 2017
Domain Driven Design - garajco Education 2017Domain Driven Design - garajco Education 2017
Domain Driven Design - garajco Education 2017
 

Recently uploaded

SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 

Recently uploaded (20)

SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 

Domain Driven Design Demonstrated

  • 1. Domain Driven Design Demonstrated Alan Christensen @christensena Christchurch Code Camp Feb 18 2012 1
  • 2. What is a Domain? 2
  • 3. What is a Domain? • “A sphere of knowledge, influence or activity”--Eric Evans 2
  • 5. What is DDD? • In order of importance: 3
  • 6. What is DDD? • In order of importance: • Design methodology 3
  • 7. What is DDD? • In order of importance: • Design methodology • Architectural style 3
  • 8. What is DDD? • In order of importance: • Design methodology • Architectural style • Set of software patterns 3
  • 9. What is DDD? • In order of importance: • Design methodology • Architectural style • Set of software patterns • “Tackling Complexity in the Heart of Software”--DDD book tagline 3
  • 12. Domain Modeling • Understand your domain • Model it in the code to suit the purpose and context for which it was intended 4
  • 13. Domain Modeling • Understand your domain • Model it in the code to suit the purpose and context for which it was intended • Leave out details and concepts that don’t add value 4
  • 14. Domain Modeling • Understand your domain • Model it in the code to suit the purpose and context for which it was intended • Leave out details and concepts that don’t add value • Keep refining “refactor to greater insight” 4
  • 15. 5
  • 18. Ubiquitous Language • Naming is important! • As is a shared understanding and consistent use of terms 6
  • 19. Ubiquitous Language • Naming is important! • As is a shared understanding and consistent use of terms • The code should use the same terms used in documents and discussion 6
  • 20. Ubiquitous Language • Naming is important! • As is a shared understanding and consistent use of terms • The code should use the same terms used in documents and discussion • Both domain experts and developers contribute to the shared language 6
  • 21. 7
  • 22. 7
  • 23. 7
  • 24. the Welsh reads "I am not in the office at the moment. Send any work to be translated." 8
  • 26. Entities 10
  • 27. Entities • Have an identity 10
  • 28. Entities • Have an identity • Identity may be determined by a natural or assigned key (e.g. Id) 10
  • 29. Entities • Have an identity • Identity may be determined by a natural or assigned key (e.g. Id) • Equals implementation to distinguish identity normally uses key 10
  • 30. Entities • Have an identity • Identity may be determined by a natural or assigned key (e.g. Id) • Equals implementation to distinguish identity normally uses key • Mutable - can be changed 10
  • 32. Value objects • No identity. Can be mixed and matched 11
  • 33. Value objects • No identity. Can be mixed and matched • Equals implemented as “all fields/properties match” 11
  • 34. Value objects • No identity. Can be mixed and matched • Equals implemented as “all fields/properties match” • Immutable - replace instead of change 11
  • 35. Worked example • What domain should we use? • Inventory? • Payroll? • Share trading? 12
  • 36. 13
  • 37. Code demo #1 • Model Driven Design • Domain Methodology • Entities and Value Objects • Invariants 14
  • 39. Invariants • Invariants ensure consistency in the domain model 15
  • 40. Invariants • Invariants ensure consistency in the domain model • They allow us to code with confidence that invalid/unnatural states are not possible 15
  • 41. Invariants • Invariants ensure consistency in the domain model • They allow us to code with confidence that invalid/unnatural states are not possible • They enforce domain rules and prevent logical fallacies 15
  • 42. Invariants • Examples • Private setters • Required constructor/factory method parameters • Exceptions for invalid operations or invalid arguments to methods 16
  • 44. Validation? • Validation is not really a domain concept. Invariants are the richer idea. 17
  • 45. Validation? • Validation is not really a domain concept. Invariants are the richer idea. • Validation should be done outside the domain to prevent invariants from ever occurring (exceptions are for exceptions) 17
  • 47. Persistence Ignorance • Persistence is a technical concern. Not part of the domain. 18
  • 48. Persistence Ignorance • Persistence is a technical concern. Not part of the domain. • Fortunately good ORM’s support Persistence Ignorance out of the box 18
  • 49. Persistence Ignorance • Persistence is a technical concern. Not part of the domain. • Fortunately good ORM’s support Persistence Ignorance out of the box • Transactions can be packaged in a “Unit of Work” concept 18
  • 51. Repositories • Semantically just “collections” with enhanced “find” functionality 19
  • 52. Repositories • Semantically just “collections” with enhanced “find” functionality • In reality they will be the “gateway” to the persistence store 19
  • 53. Repositories • Semantically just “collections” with enhanced “find” functionality • In reality they will be the “gateway” to the persistence store • Repositories are the main mechanism for Persistence Ignorance 19
  • 55. Aggregates • Some entities only make sense in the context of a parent entity or hierarchy 20
  • 56. Aggregates • Some entities only make sense in the context of a parent entity or hierarchy • Nominate specific entities as Aggregate Roots 20
  • 57. Aggregates • Some entities only make sense in the context of a parent entity or hierarchy • Nominate specific entities as Aggregate Roots • All other entities are only accessible by traversing from their aggregate roots 20
  • 58. Aggregates • Some entities only make sense in the context of a parent entity or hierarchy • Nominate specific entities as Aggregate Roots • All other entities are only accessible by traversing from their aggregate roots • Inter-aggregate relationships via queries/ lookups on repositories 20
  • 59. 21
  • 60. Code demo #2 • Repositories • Unit of Work • Fluent NHibernate AutoMapping • Session per Request 22
  • 61. 23
  • 62. Domain Services • Not general-purpose “services” (overloaded term) • Repository/UoW aware (entities are not) • Able to coordinate business processes • Most logic should still be inside entity and value objects (Domain Model) 24
  • 63. UI and Data Binding 25
  • 64. UI and Data Binding • Don’t try to data bind to anything in your domain model! 25
  • 65. UI and Data Binding • Don’t try to data bind to anything in your domain model! • Bind to “view models”, tailored to your view (MVC/MVP/MVVM) 25
  • 66. UI and Data Binding • Don’t try to data bind to anything in your domain model! • Bind to “view models”, tailored to your view (MVC/MVP/MVVM) • Read operations: Use tools like AutoMapper to map to view models 25
  • 67. UI and Data Binding • Don’t try to data bind to anything in your domain model! • Bind to “view models”, tailored to your view (MVC/MVP/MVVM) • Read operations: Use tools like AutoMapper to map to view models • Write operations: Intention/behaviour oriented. Command processor pattern works well 25
  • 69. Transports/Hydration • ORMs such as NHibernate create proxies, bypass invariants for re-hydration 26
  • 70. Transports/Hydration • ORMs such as NHibernate create proxies, bypass invariants for re-hydration • Invariants mean .NET serialisation needs to be via DTO’s. 26
  • 71. Transports/Hydration • ORMs such as NHibernate create proxies, bypass invariants for re-hydration • Invariants mean .NET serialisation needs to be via DTO’s. • DTO’s are best not as domain model clones! As with UI viewmodels, tailor for purpose. 26
  • 72. Transports/Hydration • ORMs such as NHibernate create proxies, bypass invariants for re-hydration • Invariants mean .NET serialisation needs to be via DTO’s. • DTO’s are best not as domain model clones! As with UI viewmodels, tailor for purpose. 26
  • 74. NoSQL? • DDD style aggregates can be a natural fit for document oriented databases 27
  • 75. NoSQL? • DDD style aggregates can be a natural fit for document oriented databases • No need for mapping! 27
  • 76. NoSQL? • DDD style aggregates can be a natural fit for document oriented databases • No need for mapping! • Use of event sourcing can feed same information into reporting database(s) 27
  • 77. NoSQL? • DDD style aggregates can be a natural fit for document oriented databases • No need for mapping! • Use of event sourcing can feed same information into reporting database(s) • If using relational as dual use e.g. reporting, consider the change resistance 27
  • 79. Fashions & Developments • CQRS 28
  • 80. Fashions & Developments • CQRS • Micro-ORMs 28
  • 81. Fashions & Developments • CQRS • Micro-ORMs • Repository pattern? 28
  • 82. Summary • Modeling Driven • This means designing and writing code that • expresses the domain logic • follows/enforces the domain rules • uses the domain language • databases, UI, infrastructure, etc are outside the domain 29
  • 83. 30
  • 84. Should I use DDD? • DDD over engineered for simple CRUD or mostly data oriented applications • Best suited to complex, behaviourally oriented applications • However, many of the ideas and patterns are useful in all sorts of projects 31
  • 85. Other DDD concepts • Factories • Bounded Contexts • Anti-corruption Layers • Domain Events 32
  • 86. Umpire Scorecard Over Over Player Player Delivery Run No-Ball Team Wide Innings Out Dismissal Crease Bowling Spell Boundary Country LBW Scorecard Bat-Pad Match Stumping Fall-of-Wickets Light Weather 33
  • 87. Umpire Scorecard Over Over Player Player Delivery Run No-Ball Team Wide Innings Out Dismissal Crease Bowling Spell Boundary Country LBW Scorecard Bat-Pad Match Stumping Fall-of-Wickets Light Weather 33
  • 88. References • DDD Quickly book on InfoQ bit.ly/dddquickly • Think DDD (Jak Charlton) bit.ly/thinkdddbook • Onion Architecture bit.ly/onionarch • Martin Fowler on Aggregates and NoSQL bit.ly/aggregates-nosql • My example code: github.com/christensena/DDDIntro 34
  • 89. Alan Christensen @christensena 35

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n
  65. \n
  66. \n
  67. \n
  68. \n
  69. \n
  70. \n
  71. \n
  72. \n