SlideShare a Scribd company logo
1 of 42
Domain Driven
   Design



     Tim Mahy
timm@infosupport.com
Content
 Why ?                         Patterns (demo)
 What ?                        –   Modules
 Where ?                       –   The domain objects
                               –   Aggregates
 Fundamentals
                               –   Repositories
 –   The domain
                               –   Factories
 –   The model
                               –   Specification
 –   The domain model
                               –   Anti corruption layer
 –   The ubiquitous language
 –   The bounded context
                               Best practices
Warning
Why ?

        The critical complexity of
         most software projects
         is in understanding the
         business domain itself.
What ?
Domain Driven design is not a technology or a
              methodology.

      It’s a way of thinking and a set of
  priorities, aimed at accelerating software
 projects that have to deal with complicated
                    domains
What ?
 Guidance upon a proven technique
 – Patterns to keep domain consistent and clean
 – Strategies on development responsibility and
   integrity
 – Principles & practices for the development
   process
Where ?
 High business complexity
 Works well for business services inside a SOA
The fundamentals
 The domain
 The model
 The domain model
 The ubiquitous language
 The bounded context
The domain

 A sphere of knowledge, influence, or activity.

 The subject area to which the user applies a
    program is the domain of the software.
The model

        A system of abstractions
         that describes selected
           aspects of a domain
        and can be used to solve
    problems related to that domain.
The domain model
 What needs to be build
 Distilled knowledge about the domain
 – For the scope of the project
 – Consists of a language that is spoken by the whole
   team AND the business!
The domain model
 The model and the heart of the design shape
 each other
 – They are linked
 – Understanding the model allows you to interpret
   the code
The ubiquitous language
 Common language between IT and business
 – Avoid miscommunication
 – Based upon a shared conceptual model
 – Close to domain experts & developers
 – Free of misconceptions or contradictions
 The language of the team
 – Accept and learn together
 – Refine understanding over time
 – Iron out misconceptions and contradictions
 – To ensure that all members have the same
   understanding of the words used over time
The bounded context
 One model to rule them all is a non cost-
 effective dream
 Create boundaries based upon the
 context, the model will only be valid inside
 this boundaries
 Context map to model relationships between
 multiple models
 Conceptual splinters indicate different model
 – Duplicate concepts
 – False cognates
Knowledge rich design
 It’s more than ‘finding nouns’
 Not only about entities but also about rules &
 constraints
 Implicit concepts should be explicit
 Knowledge in the design is a developers best
 documentation
 Supple design ready for refactoring
The essence
 Seperate
 – Business logic
 – Infrastructure
The patterns
 Modules
 The domain objects
 – Entities
 – Value types
 – Services
 Aggregates
 Repositories
 Factories
 Specification
 Anti corruption layer
Modules
 Functional partitions inside a domain model
 Should be part of the ubiquitous language

 Example:
 – Reference Data
    • Logistics
    • Procurement
    • Organisation
The domain objects
 Entities
 Value objects
 Services
The domain objects
 Entities
 – Data & behavior
 – Not your persistance entities (no DTO)
 – Functional identity
The domain objects
 Value objects
 – Value = combination of all values
 – Have no identity


 Try to make
 – Immutable
 – Copied when exposed on a client so that the client
   can hold on to them (<> entities)
The domain objects
 Services
 – Encapsulate business logic
 – Cross entity logic
 – Correspond to verbs in the ubiquitous language
 – Stateless


 Try to limit
Aggregates
 Combination of entities & value objects
 One entity is ‘root’ of the aggregate
 Ensures consistent state & data integrity
 Root entity is navigational start for other data
 (via associations)
Aggregates
 Client code cannot make changes to parts of
 the aggregate unless it uses methods on the
 aggregate root.
 Entities and value objects in an aggregate can
 only hold references to other aggregate roots.
Factories
 Build up aggregates
 (Abstract) Factory pattern
 Not always needed
 Mostly with a fluent API interface
 May break encapsulation
 Must ensure atomic creation & invariants
 Think of identity creation
Repositories
 Exposes query possibilities in an in-memory
 style database of root aggregates
 Interface = model
 Implementation = infrastructure
 Responsible for UOW, Change Tracking…
Specification
 Place business rules inside predicate objects
 Can be used as predicates to factory or
 repositories
 Can be used to evaluate conditions
Specification
Specification
If ( customer.NumberOfOrders > 100 && customer.NumberOfDelayedPayment == 0)
{
…..
}


If( new ThrustedCustomer().IsSatifiedBy( customer ))
{
…..
}


If( new ThrustedCustomer().Or( new VeryRichCustomer() ).IsSatifiedBy( customer ))
{
…..
}
Anti-corruption layer
 Bridges the layer to other worlds
 Traditional: mapping to bridge
 communications
 Bridge between different bounded contexts
Do
 Domain objects can also represent a process
 Keep refactoring to keep clean code

customer.Address = new Address( …

customer.MoveToNewAddress( new Address …
Do
Work always test first
 – Enhances your ‘client’ API
Use terms of the ubiquitous for your
class/interface names
Strive towords command query responsibility
seggregation to divide operations
Use code contracts
Split functional keys from entities
Make generic value types
Do
Try to write BDD tests:
 – When
 – Given
 – Then
Do
Implement cohesive mechanisms
 – Generic: Time slicing, Graph traversal, History
 – Seperate framework
 – Try to go declarative
Don’t be afraid of generic subdomains
 – Reference data not specific to the problem
   domain
Segregate the core from the less important
parts
Abstract core?
Do
   Apply SOLID principles very strict
newStatus = 3; // Gold
Customer.Update(newStatus, null);



Customer.UpgradeToGoldStatus();
Do
Closure of operations

Pigment red = new Pigment();
Pigment blue = new Pigment();
Pigment purple= red.Mix(blue);
Do
Declarative programming is a programming style where the
specification becomes executable
 – Either by an interpreted language like a DSL or runtime code
   generation
     • This technique has a lot of merits
     • But can impose some risks as well
 – Many of the benefits of a declarative design can be reached as well by
   combining
     • intention-revealing interfaces, side effect-free functions, conceptual contours and
       closure of operations
     • A fully implemented specification pattern:
       var isAllowedToDrive = IsOlderThan(18) & DoesNotDrink();


     • Or a fluent interface
       c = new CustomerBuilder()
            .AsGoldCustomer()
            .WithInitialBalanceOf(100.Euros());
Don’t
 Do only some of the patterns
 Start without reading
Questions
CQRS
Command
Query
Responsibility
Seggregation
UI DataStore
     Queries
                                           Subscribe




UI   Commands
                                               EventBus


                Business Logic       Publish



                Truth (optional)

More Related Content

Viewers also liked

DDD patterns that were not in the book
DDD patterns that were not in the bookDDD patterns that were not in the book
DDD patterns that were not in the bookCyrille Martraire
 
Beyond design patterns and principles - writing good OO code
Beyond design patterns and principles - writing good OO codeBeyond design patterns and principles - writing good OO code
Beyond design patterns and principles - writing good OO codeMatthias Noback
 
Domain-Driven Design with ASP.NET MVC
Domain-Driven Design with ASP.NET MVCDomain-Driven Design with ASP.NET MVC
Domain-Driven Design with ASP.NET MVCSteven Smith
 
Domain-Driven Design (Artur Trosin Product Stream)
Domain-Driven Design (Artur Trosin Product Stream)Domain-Driven Design (Artur Trosin Product Stream)
Domain-Driven Design (Artur Trosin Product Stream)IT Arena
 
Solid principles, Design Patterns, and Domain Driven Design
Solid principles, Design Patterns, and Domain Driven DesignSolid principles, Design Patterns, and Domain Driven Design
Solid principles, Design Patterns, and Domain Driven DesignIrwansyah Irwansyah
 
Domain Driven Design Quickly
Domain Driven Design QuicklyDomain Driven Design Quickly
Domain Driven Design QuicklyMariam Hakobyan
 
Principles of microservices velocity
Principles of microservices   velocityPrinciples of microservices   velocity
Principles of microservices velocitySam Newman
 

Viewers also liked (8)

DDD patterns that were not in the book
DDD patterns that were not in the bookDDD patterns that were not in the book
DDD patterns that were not in the book
 
Beyond design patterns and principles - writing good OO code
Beyond design patterns and principles - writing good OO codeBeyond design patterns and principles - writing good OO code
Beyond design patterns and principles - writing good OO code
 
Domain-Driven Design with ASP.NET MVC
Domain-Driven Design with ASP.NET MVCDomain-Driven Design with ASP.NET MVC
Domain-Driven Design with ASP.NET MVC
 
Domain-Driven Design (Artur Trosin Product Stream)
Domain-Driven Design (Artur Trosin Product Stream)Domain-Driven Design (Artur Trosin Product Stream)
Domain-Driven Design (Artur Trosin Product Stream)
 
Architecting iOS Project
Architecting iOS ProjectArchitecting iOS Project
Architecting iOS Project
 
Solid principles, Design Patterns, and Domain Driven Design
Solid principles, Design Patterns, and Domain Driven DesignSolid principles, Design Patterns, and Domain Driven Design
Solid principles, Design Patterns, and Domain Driven Design
 
Domain Driven Design Quickly
Domain Driven Design QuicklyDomain Driven Design Quickly
Domain Driven Design Quickly
 
Principles of microservices velocity
Principles of microservices   velocityPrinciples of microservices   velocity
Principles of microservices velocity
 

Similar to Domain Driven Design Fundamentals and Patterns

Domain Driven Design Introduction
Domain Driven Design IntroductionDomain Driven Design Introduction
Domain Driven Design Introductionwojtek_s
 
RailswayCon 2010 - Command Your Domain
RailswayCon 2010 - Command Your DomainRailswayCon 2010 - Command Your Domain
RailswayCon 2010 - Command Your DomainLourens Naudé
 
Domain Driven Design & Hexagonal Architecture
Domain Driven Design & Hexagonal ArchitectureDomain Driven Design & Hexagonal Architecture
Domain Driven Design & Hexagonal ArchitectureCan Pekdemir
 
ITARC15 Workshop - Architecting a Large Software Project - Lessons Learned
ITARC15 Workshop - Architecting a Large Software Project - Lessons LearnedITARC15 Workshop - Architecting a Large Software Project - Lessons Learned
ITARC15 Workshop - Architecting a Large Software Project - Lessons LearnedJoão Pedro Martins
 
An Introduction to Domain Driven Design in PHP
An Introduction to Domain Driven Design in PHPAn Introduction to Domain Driven Design in PHP
An Introduction to Domain Driven Design in PHPChris Renner
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven DesignMuhammad Ali
 
D2 domain driven-design
D2 domain driven-designD2 domain driven-design
D2 domain driven-designArnaud Bouchez
 
Architecting a Large Software Project - Lessons Learned
Architecting a Large Software Project - Lessons LearnedArchitecting a Large Software Project - Lessons Learned
Architecting a Large Software Project - Lessons LearnedJoão Pedro Martins
 
Model Driven Architectures
Model Driven ArchitecturesModel Driven Architectures
Model Driven ArchitecturesLalit Kale
 
Building Maintainable PHP Applications.pptx
Building Maintainable PHP Applications.pptxBuilding Maintainable PHP Applications.pptx
Building Maintainable PHP Applications.pptxdavorminchorov1
 
Elements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code FirstElements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code FirstEnea Gabriel
 
MOND Semantics Integration
MOND Semantics IntegrationMOND Semantics Integration
MOND Semantics IntegrationSales Emea
 
Seminar - Scalable Enterprise Application Development Using DDD and CQRS
Seminar - Scalable Enterprise Application Development Using DDD and CQRSSeminar - Scalable Enterprise Application Development Using DDD and CQRS
Seminar - Scalable Enterprise Application Development Using DDD and CQRSMizanur Sarker
 
Latest trends in information technology
Latest trends in information technologyLatest trends in information technology
Latest trends in information technologyEldos Kuriakose
 
Building the Case for New Technology Have Inspiration, Will Travel ...
Building the Case for New Technology Have Inspiration, Will Travel ...Building the Case for New Technology Have Inspiration, Will Travel ...
Building the Case for New Technology Have Inspiration, Will Travel ...Society of Women Engineers
 

Similar to Domain Driven Design Fundamentals and Patterns (20)

Domain Driven Design Introduction
Domain Driven Design IntroductionDomain Driven Design Introduction
Domain Driven Design Introduction
 
RailswayCon 2010 - Command Your Domain
RailswayCon 2010 - Command Your DomainRailswayCon 2010 - Command Your Domain
RailswayCon 2010 - Command Your Domain
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Domain Driven Design & Hexagonal Architecture
Domain Driven Design & Hexagonal ArchitectureDomain Driven Design & Hexagonal Architecture
Domain Driven Design & Hexagonal Architecture
 
ITARC15 Workshop - Architecting a Large Software Project - Lessons Learned
ITARC15 Workshop - Architecting a Large Software Project - Lessons LearnedITARC15 Workshop - Architecting a Large Software Project - Lessons Learned
ITARC15 Workshop - Architecting a Large Software Project - Lessons Learned
 
An Introduction to Domain Driven Design in PHP
An Introduction to Domain Driven Design in PHPAn Introduction to Domain Driven Design in PHP
An Introduction to Domain Driven Design in PHP
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
D2 domain driven-design
D2 domain driven-designD2 domain driven-design
D2 domain driven-design
 
Architecting a Large Software Project - Lessons Learned
Architecting a Large Software Project - Lessons LearnedArchitecting a Large Software Project - Lessons Learned
Architecting a Large Software Project - Lessons Learned
 
Model Driven Architectures
Model Driven ArchitecturesModel Driven Architectures
Model Driven Architectures
 
Building Maintainable PHP Applications.pptx
Building Maintainable PHP Applications.pptxBuilding Maintainable PHP Applications.pptx
Building Maintainable PHP Applications.pptx
 
Elements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code FirstElements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code First
 
Lets focus on business value
Lets focus on business valueLets focus on business value
Lets focus on business value
 
MOND Semantics Integration
MOND Semantics IntegrationMOND Semantics Integration
MOND Semantics Integration
 
Seminar - Scalable Enterprise Application Development Using DDD and CQRS
Seminar - Scalable Enterprise Application Development Using DDD and CQRSSeminar - Scalable Enterprise Application Development Using DDD and CQRS
Seminar - Scalable Enterprise Application Development Using DDD and CQRS
 
Latest trends in information technology
Latest trends in information technologyLatest trends in information technology
Latest trends in information technology
 
L05 Design Patterns
L05 Design PatternsL05 Design Patterns
L05 Design Patterns
 
Building the Case for New Technology Have Inspiration, Will Travel ...
Building the Case for New Technology Have Inspiration, Will Travel ...Building the Case for New Technology Have Inspiration, Will Travel ...
Building the Case for New Technology Have Inspiration, Will Travel ...
 
Lets focus on business value
Lets focus on business valueLets focus on business value
Lets focus on business value
 
Lets focus on business value
Lets focus on business valueLets focus on business value
Lets focus on business value
 

More from Tim Mahy

2013 training - tim m - cross cutting concerns
2013   training - tim m - cross cutting concerns2013   training - tim m - cross cutting concerns
2013 training - tim m - cross cutting concernsTim Mahy
 
2009 seminar - tim m - vs 2010 developer edition
2009   seminar - tim m - vs 2010 developer edition2009   seminar - tim m - vs 2010 developer edition
2009 seminar - tim m - vs 2010 developer editionTim Mahy
 
2009 training - tim m - object oriented programming
2009   training - tim m - object oriented programming2009   training - tim m - object oriented programming
2009 training - tim m - object oriented programmingTim Mahy
 
2010 iska - tim m - functioneel programmeren in c-sharp
2010   iska - tim m - functioneel programmeren in c-sharp2010   iska - tim m - functioneel programmeren in c-sharp
2010 iska - tim m - functioneel programmeren in c-sharpTim Mahy
 
2010 iska - tim m - nosql iska
2010   iska - tim m - nosql iska2010   iska - tim m - nosql iska
2010 iska - tim m - nosql iskaTim Mahy
 
2012 student track - vs2010
2012   student track - vs20102012   student track - vs2010
2012 student track - vs2010Tim Mahy
 
communityday 2012 - cqrs
communityday 2012 - cqrscommunityday 2012 - cqrs
communityday 2012 - cqrsTim Mahy
 
CQRS & Queue unlimited
CQRS & Queue unlimitedCQRS & Queue unlimited
CQRS & Queue unlimitedTim Mahy
 

More from Tim Mahy (8)

2013 training - tim m - cross cutting concerns
2013   training - tim m - cross cutting concerns2013   training - tim m - cross cutting concerns
2013 training - tim m - cross cutting concerns
 
2009 seminar - tim m - vs 2010 developer edition
2009   seminar - tim m - vs 2010 developer edition2009   seminar - tim m - vs 2010 developer edition
2009 seminar - tim m - vs 2010 developer edition
 
2009 training - tim m - object oriented programming
2009   training - tim m - object oriented programming2009   training - tim m - object oriented programming
2009 training - tim m - object oriented programming
 
2010 iska - tim m - functioneel programmeren in c-sharp
2010   iska - tim m - functioneel programmeren in c-sharp2010   iska - tim m - functioneel programmeren in c-sharp
2010 iska - tim m - functioneel programmeren in c-sharp
 
2010 iska - tim m - nosql iska
2010   iska - tim m - nosql iska2010   iska - tim m - nosql iska
2010 iska - tim m - nosql iska
 
2012 student track - vs2010
2012   student track - vs20102012   student track - vs2010
2012 student track - vs2010
 
communityday 2012 - cqrs
communityday 2012 - cqrscommunityday 2012 - cqrs
communityday 2012 - cqrs
 
CQRS & Queue unlimited
CQRS & Queue unlimitedCQRS & Queue unlimited
CQRS & Queue unlimited
 

Recently uploaded

Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 

Recently uploaded (20)

Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 

Domain Driven Design Fundamentals and Patterns

  • 1. Domain Driven Design Tim Mahy timm@infosupport.com
  • 2. Content Why ? Patterns (demo) What ? – Modules Where ? – The domain objects – Aggregates Fundamentals – Repositories – The domain – Factories – The model – Specification – The domain model – Anti corruption layer – The ubiquitous language – The bounded context Best practices
  • 4. Why ? The critical complexity of most software projects is in understanding the business domain itself.
  • 5. What ? Domain Driven design is not a technology or a methodology. It’s a way of thinking and a set of priorities, aimed at accelerating software projects that have to deal with complicated domains
  • 6. What ? Guidance upon a proven technique – Patterns to keep domain consistent and clean – Strategies on development responsibility and integrity – Principles & practices for the development process
  • 7. Where ? High business complexity Works well for business services inside a SOA
  • 8. The fundamentals The domain The model The domain model The ubiquitous language The bounded context
  • 9. The domain A sphere of knowledge, influence, or activity. The subject area to which the user applies a program is the domain of the software.
  • 10. The model A system of abstractions that describes selected aspects of a domain and can be used to solve problems related to that domain.
  • 11. The domain model What needs to be build Distilled knowledge about the domain – For the scope of the project – Consists of a language that is spoken by the whole team AND the business!
  • 12. The domain model The model and the heart of the design shape each other – They are linked – Understanding the model allows you to interpret the code
  • 13. The ubiquitous language Common language between IT and business – Avoid miscommunication – Based upon a shared conceptual model – Close to domain experts & developers – Free of misconceptions or contradictions The language of the team – Accept and learn together – Refine understanding over time – Iron out misconceptions and contradictions – To ensure that all members have the same understanding of the words used over time
  • 14. The bounded context One model to rule them all is a non cost- effective dream Create boundaries based upon the context, the model will only be valid inside this boundaries Context map to model relationships between multiple models Conceptual splinters indicate different model – Duplicate concepts – False cognates
  • 15. Knowledge rich design It’s more than ‘finding nouns’ Not only about entities but also about rules & constraints Implicit concepts should be explicit Knowledge in the design is a developers best documentation Supple design ready for refactoring
  • 16. The essence Seperate – Business logic – Infrastructure
  • 17. The patterns Modules The domain objects – Entities – Value types – Services Aggregates Repositories Factories Specification Anti corruption layer
  • 18. Modules Functional partitions inside a domain model Should be part of the ubiquitous language Example: – Reference Data • Logistics • Procurement • Organisation
  • 19. The domain objects Entities Value objects Services
  • 20. The domain objects Entities – Data & behavior – Not your persistance entities (no DTO) – Functional identity
  • 21. The domain objects Value objects – Value = combination of all values – Have no identity Try to make – Immutable – Copied when exposed on a client so that the client can hold on to them (<> entities)
  • 22. The domain objects Services – Encapsulate business logic – Cross entity logic – Correspond to verbs in the ubiquitous language – Stateless Try to limit
  • 23. Aggregates Combination of entities & value objects One entity is ‘root’ of the aggregate Ensures consistent state & data integrity Root entity is navigational start for other data (via associations)
  • 24. Aggregates Client code cannot make changes to parts of the aggregate unless it uses methods on the aggregate root. Entities and value objects in an aggregate can only hold references to other aggregate roots.
  • 25. Factories Build up aggregates (Abstract) Factory pattern Not always needed Mostly with a fluent API interface May break encapsulation Must ensure atomic creation & invariants Think of identity creation
  • 26. Repositories Exposes query possibilities in an in-memory style database of root aggregates Interface = model Implementation = infrastructure Responsible for UOW, Change Tracking…
  • 27. Specification Place business rules inside predicate objects Can be used as predicates to factory or repositories Can be used to evaluate conditions
  • 29. Specification If ( customer.NumberOfOrders > 100 && customer.NumberOfDelayedPayment == 0) { ….. }  If( new ThrustedCustomer().IsSatifiedBy( customer )) { ….. }  If( new ThrustedCustomer().Or( new VeryRichCustomer() ).IsSatifiedBy( customer )) { ….. }
  • 30. Anti-corruption layer Bridges the layer to other worlds Traditional: mapping to bridge communications Bridge between different bounded contexts
  • 31. Do Domain objects can also represent a process Keep refactoring to keep clean code customer.Address = new Address( …  customer.MoveToNewAddress( new Address …
  • 32. Do Work always test first – Enhances your ‘client’ API Use terms of the ubiquitous for your class/interface names Strive towords command query responsibility seggregation to divide operations Use code contracts Split functional keys from entities Make generic value types
  • 33. Do Try to write BDD tests: – When – Given – Then
  • 34. Do Implement cohesive mechanisms – Generic: Time slicing, Graph traversal, History – Seperate framework – Try to go declarative Don’t be afraid of generic subdomains – Reference data not specific to the problem domain Segregate the core from the less important parts Abstract core?
  • 35. Do Apply SOLID principles very strict newStatus = 3; // Gold Customer.Update(newStatus, null); Customer.UpgradeToGoldStatus();
  • 36. Do Closure of operations Pigment red = new Pigment(); Pigment blue = new Pigment(); Pigment purple= red.Mix(blue);
  • 37. Do Declarative programming is a programming style where the specification becomes executable – Either by an interpreted language like a DSL or runtime code generation • This technique has a lot of merits • But can impose some risks as well – Many of the benefits of a declarative design can be reached as well by combining • intention-revealing interfaces, side effect-free functions, conceptual contours and closure of operations • A fully implemented specification pattern: var isAllowedToDrive = IsOlderThan(18) & DoesNotDrink(); • Or a fluent interface c = new CustomerBuilder() .AsGoldCustomer() .WithInitialBalanceOf(100.Euros());
  • 38. Don’t Do only some of the patterns Start without reading
  • 41.
  • 42. UI DataStore Queries Subscribe UI Commands EventBus Business Logic Publish Truth (optional)