SlideShare a Scribd company logo
Domain Driven Design
Josh Dastmalchi
Let’s Drive a Manual Car
How do we shift gears?
• Press the clutch pedal to the floor
• Use the gear shift to change gears
• Depress the clutch pedal while also pressing the gas pedal
Okay, Let’s Drive!
The Importance of Why, What, When
Priorities
Correctness
• If it doesn’t do what we intended, we have failed.
• Testability – how do I know I’m correct?
Ease of Change
• Software is never done.
• An anecdote: “This requirement will definitely never change”
Methods
Ubiquitous Language
• To achieve correctness, we must communicate the product needs.
• If we're not speaking the same language, we're off to a bad start.
• What if we all had different native languages?
The Boot
Contextless Truth
• The truth of a domain exists outside of any user interface or database.
• Use Cases:
• The domain defines truth - what is possible in reality
• A use case defines what is possible in the application
Patterns
• Establishing patterns takes the mystery away from doing common tasks.
• Command-Query Responsibility Segregation
• Repository
• Hexagonal
The Code
What everyone really wants to see
Domain Events
Represents a change of state in our domain.
• All domain mutations produce domain events recording them.
• Event handlers can listen for these events and perform actions accordingly
• Enables event sourcing, a powerful but complex way to store domain history.
Domain Driven Design Belfast Meetup - Overview, Lessons and Examples by Josh Dastmalchi
Domain Driven Design Belfast Meetup - Overview, Lessons and Examples by Josh Dastmalchi
Domain Events: My experience
• They won’t feel useful initially – but they unlock a lot of power for later
complexity.
• Generally there are two types of handlers:
• Handlers that enforce domain rules of the form “When x, then y”
• Handlers that inform other systems of changes in our domain
• Include enough information in events to make them reversible
• Prefer domain services or entities to event handlers
Entities
Represents a concept in our domain.
• Has an immutable unique identifier.
• Enforces invariants (domain rules) and never allows itself to be in an invalid state.
Aggregates
Aggregates are a special type of entity.
• An aggregate cannot be nested in another entity's object graph.
• An aggregate can be referenced by ID by another entity.
• Non-aggregate entities do not track events.
• Non-aggregate entities do not have public methods.
Domain Driven Design Belfast Meetup - Overview, Lessons and Examples by Josh Dastmalchi
Domain Driven Design Belfast Meetup - Overview, Lessons and Examples by Josh Dastmalchi
Domain Driven Design Belfast Meetup - Overview, Lessons and Examples by Josh Dastmalchi
Domain Driven Design Belfast Meetup - Overview, Lessons and Examples by Josh Dastmalchi
Domain Driven Design Belfast Meetup - Overview, Lessons and Examples by Josh Dastmalchi
Domain Driven Design Belfast Meetup - Overview, Lessons and Examples by Josh Dastmalchi
Domain Driven Design Belfast Meetup - Overview, Lessons and Examples by Josh Dastmalchi
Aggregates: My Experience
• Minimize aggregate size.
• (Almost) never use non-aggregate entities.
Value Objects
Represents a complex property in our domain.
• In contrast to entities, equality is determined by a value object’s properties, not a
unique identifier.
• Like entities, these are self-validating.
Domain Driven Design Belfast Meetup - Overview, Lessons and Examples by Josh Dastmalchi
Domain Driven Design Belfast Meetup - Overview, Lessons and Examples by Josh Dastmalchi
Domain Driven Design Belfast Meetup - Overview, Lessons and Examples by Josh Dastmalchi
Domain Driven Design Belfast Meetup - Overview, Lessons and Examples by Josh Dastmalchi
Domain Driven Design Belfast Meetup - Overview, Lessons and Examples by Josh Dastmalchi
Value Objects: My Experience
• For primitive types, always consider wrapping them in a value object.
• If an entity has complex validation across multiple properties, consider wrapping
them all together as a value object.
• Wrapping your aggregate identifiers as value objects provides type safety in a
place where it is very easy to make mistakes.
Domain Service
• An implementation of orchestrated domain logic that can’t be put on an
aggregate
• Common reasons to use a service:
• Uniqueness checks
• Configuration-based logic
• Interaction with multiple aggregates
Domain Driven Design Belfast Meetup - Overview, Lessons and Examples by Josh Dastmalchi
Domain Driven Design Belfast Meetup - Overview, Lessons and Examples by Josh Dastmalchi
Domain Driven Design Belfast Meetup - Overview, Lessons and Examples by Josh Dastmalchi
Domain Driven Design Belfast Meetup - Overview, Lessons and Examples by Josh Dastmalchi
Domain Driven Design Belfast Meetup - Overview, Lessons and Examples by Josh Dastmalchi
Domain Driven Design Belfast Meetup - Overview, Lessons and Examples by Josh Dastmalchi
Domain Services: My Experience
• Use single-purpose services and composition instead of large services
• Avoid an anemic domain: prefer entity-based logic over service-based logic
• If an entity method requires service orchestration, use access modifiers to prevent
non-domain calls
Major Takeaways: Why
Priorities
1. Correctness
2. Ease of change
Methods
• Ubiquitous language
• Contextless truth
Major Takeaways: How
• Domain design: Correctness & Ease of Change
• Domain logic: Entity > Service > Event Handler
• Small entities, small services
Live Demo
Real Practice – Adapting the Domain
• A doctor’s name must be at least 3 characters, can be no more than 50 characters, and
must consist of only alphanumeric characters.
• An appointment can only be scheduled in increments of 15 minutes. Specifically,
appointment times must end in :00, :15, :30, or :45.
• Doctors get days off – holidays, time off, etc. We should add a concept of a doctor’s
time off that specifies a date and hours on that date during which a doctor is
unavailable. This should prevent appointments being scheduled during that time and
delete any existing appointments during that time. Time off should only be able to be
scheduled in the future.
Links
• Source Code: https://github.com/josh-dastmalchi/ddd-example

More Related Content

PDF
Patterns of Distributed Application Design
PDF
Graphel: A Purely Functional Approach to Digital Interaction
PPTX
Patterns of Distributed Application Design
PPTX
presentation on property buy and sell
PPTX
YTD Video Downloader Pro Crack [Latest 2025]
PPTX
Distributed systems: design, principles and experiencies
PPTX
Breaking it Down: Microservices Architecture for PHP Developers
PPTX
CPP19 - Revision
Patterns of Distributed Application Design
Graphel: A Purely Functional Approach to Digital Interaction
Patterns of Distributed Application Design
presentation on property buy and sell
YTD Video Downloader Pro Crack [Latest 2025]
Distributed systems: design, principles and experiencies
Breaking it Down: Microservices Architecture for PHP Developers
CPP19 - Revision

Similar to Domain Driven Design Belfast Meetup - Overview, Lessons and Examples by Josh Dastmalchi (20)

PDF
Page Objects - You're Doing it Wrong by Titus Fortner
PPTX
Project presentation
PPTX
Why All the Buzz About Database Integration Solutions?
PPTX
Making a Mock by Kelsey Shannahan
PPTX
What are microservices
PPTX
Grokking microservices in 5 minutes
PPT
Domain Driven Design (DDD)
PDF
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...
PPT
2.IntelligentAgents.ppt
PPTX
operating system notes of unit 3 explanation
PPTX
Generating unit tests based on user logs
PPTX
Dealing With The Input Providers
PPTX
Using Hystrix to Build Resilient Distributed Systems
PPTX
Grails Services
PPTX
Microservices: Yes or not?
PPTX
User Story Writing & Estimation For Testers By Mahesh Varadharajan
PPT
Designing agents as if people mattered
PDF
Software design with Domain-driven design
PPTX
Practical Agile. Lessons learned the hard way on our journey building digita...
PPTX
Practical agile TechExeter
Page Objects - You're Doing it Wrong by Titus Fortner
Project presentation
Why All the Buzz About Database Integration Solutions?
Making a Mock by Kelsey Shannahan
What are microservices
Grokking microservices in 5 minutes
Domain Driven Design (DDD)
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...
2.IntelligentAgents.ppt
operating system notes of unit 3 explanation
Generating unit tests based on user logs
Dealing With The Input Providers
Using Hystrix to Build Resilient Distributed Systems
Grails Services
Microservices: Yes or not?
User Story Writing & Estimation For Testers By Mahesh Varadharajan
Designing agents as if people mattered
Software design with Domain-driven design
Practical Agile. Lessons learned the hard way on our journey building digita...
Practical agile TechExeter
Ad

Recently uploaded (20)

PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
ai tools demonstartion for schools and inter college
PPTX
L1 - Introduction to python Backend.pptx
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
Reimagine Home Health with the Power of Agentic AI​
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
top salesforce developer skills in 2025.pdf
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
Design an Analysis of Algorithms II-SECS-1021-03
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Odoo Companies in India – Driving Business Transformation.pdf
ai tools demonstartion for schools and inter college
L1 - Introduction to python Backend.pptx
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
CHAPTER 2 - PM Management and IT Context
Upgrade and Innovation Strategies for SAP ERP Customers
Odoo POS Development Services by CandidRoot Solutions
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Softaken Excel to vCard Converter Software.pdf
Reimagine Home Health with the Power of Agentic AI​
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Design an Analysis of Algorithms I-SECS-1021-03
Operating system designcfffgfgggggggvggggggggg
VVF-Customer-Presentation2025-Ver1.9.pptx
top salesforce developer skills in 2025.pdf
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Navsoft: AI-Powered Business Solutions & Custom Software Development
2025 Textile ERP Trends: SAP, Odoo & Oracle
Ad

Domain Driven Design Belfast Meetup - Overview, Lessons and Examples by Josh Dastmalchi

  • 2. Let’s Drive a Manual Car
  • 3. How do we shift gears? • Press the clutch pedal to the floor • Use the gear shift to change gears • Depress the clutch pedal while also pressing the gas pedal
  • 5. The Importance of Why, What, When
  • 7. Correctness • If it doesn’t do what we intended, we have failed. • Testability – how do I know I’m correct?
  • 8. Ease of Change • Software is never done. • An anecdote: “This requirement will definitely never change”
  • 10. Ubiquitous Language • To achieve correctness, we must communicate the product needs. • If we're not speaking the same language, we're off to a bad start. • What if we all had different native languages?
  • 12. Contextless Truth • The truth of a domain exists outside of any user interface or database. • Use Cases: • The domain defines truth - what is possible in reality • A use case defines what is possible in the application
  • 13. Patterns • Establishing patterns takes the mystery away from doing common tasks. • Command-Query Responsibility Segregation • Repository • Hexagonal
  • 14. The Code What everyone really wants to see
  • 15. Domain Events Represents a change of state in our domain. • All domain mutations produce domain events recording them. • Event handlers can listen for these events and perform actions accordingly • Enables event sourcing, a powerful but complex way to store domain history.
  • 18. Domain Events: My experience • They won’t feel useful initially – but they unlock a lot of power for later complexity. • Generally there are two types of handlers: • Handlers that enforce domain rules of the form “When x, then y” • Handlers that inform other systems of changes in our domain • Include enough information in events to make them reversible • Prefer domain services or entities to event handlers
  • 19. Entities Represents a concept in our domain. • Has an immutable unique identifier. • Enforces invariants (domain rules) and never allows itself to be in an invalid state.
  • 20. Aggregates Aggregates are a special type of entity. • An aggregate cannot be nested in another entity's object graph. • An aggregate can be referenced by ID by another entity. • Non-aggregate entities do not track events. • Non-aggregate entities do not have public methods.
  • 28. Aggregates: My Experience • Minimize aggregate size. • (Almost) never use non-aggregate entities.
  • 29. Value Objects Represents a complex property in our domain. • In contrast to entities, equality is determined by a value object’s properties, not a unique identifier. • Like entities, these are self-validating.
  • 35. Value Objects: My Experience • For primitive types, always consider wrapping them in a value object. • If an entity has complex validation across multiple properties, consider wrapping them all together as a value object. • Wrapping your aggregate identifiers as value objects provides type safety in a place where it is very easy to make mistakes.
  • 36. Domain Service • An implementation of orchestrated domain logic that can’t be put on an aggregate • Common reasons to use a service: • Uniqueness checks • Configuration-based logic • Interaction with multiple aggregates
  • 43. Domain Services: My Experience • Use single-purpose services and composition instead of large services • Avoid an anemic domain: prefer entity-based logic over service-based logic • If an entity method requires service orchestration, use access modifiers to prevent non-domain calls
  • 44. Major Takeaways: Why Priorities 1. Correctness 2. Ease of change Methods • Ubiquitous language • Contextless truth
  • 45. Major Takeaways: How • Domain design: Correctness & Ease of Change • Domain logic: Entity > Service > Event Handler • Small entities, small services
  • 47. Real Practice – Adapting the Domain • A doctor’s name must be at least 3 characters, can be no more than 50 characters, and must consist of only alphanumeric characters. • An appointment can only be scheduled in increments of 15 minutes. Specifically, appointment times must end in :00, :15, :30, or :45. • Doctors get days off – holidays, time off, etc. We should add a concept of a doctor’s time off that specifies a date and hours on that date during which a doctor is unavailable. This should prevent appointments being scheduled during that time and delete any existing appointments during that time. Time off should only be able to be scheduled in the future.
  • 48. Links • Source Code: https://github.com/josh-dastmalchi/ddd-example