SlideShare uma empresa Scribd logo
1 de 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)

Mais conteúdo relacionado

Destaque

Principles of microservices velocity
Principles of microservices   velocityPrinciples of microservices   velocity
Principles of microservices velocity
Sam Newman
 

Destaque (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
 

Semelhante a 2011 iska - tim m - domain driven design

RailswayCon 2010 - Command Your Domain
RailswayCon 2010 - Command Your DomainRailswayCon 2010 - Command Your Domain
RailswayCon 2010 - Command Your Domain
Lourens Naudé
 
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
Mizanur Sarker
 

Semelhante a 2011 iska - tim m - domain driven design (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
 

Mais de 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
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Último (20)

Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
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
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
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
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 

2011 iska - tim m - domain driven design

  • 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)