SlideShare ist ein Scribd-Unternehmen logo
1 von 45
Downloaden Sie, um offline zu lesen
Harsh Jegadeesan’s CLASSROOM




DOMAIN-DRIVEN DESIGN




                                 BITS Pilani
                                 Off-Campus Work-Integrated Learning Programmes
AGENDA

Why Domain-Driven Design?
Core Patterns
ERIC EVANS SPEAKS
 Eric Evans, the author of Domain-Driven Design, has
 been programming and designing systems for 25
 years
 He asserts that for most software projects, the
 primary focus should be on the domain and domain
 logic
 “Domain-driven design flows from the premise that the heart of
 software development is knowledge of the subject matter and
 finding useful ways of understanding that subject matter. The
 complexity that we should be tackling is the complexity of the
 domain itself -- not the technical architecture, not the user
 interface, not even specific features. This means designing
 everything around our understanding and conception of the most
 essential concepts of the business and justifying any other
 development by how it supports that core.”

 From http://domaindrivendesign.org/articles/blog/evans_eric_ddd_and_mdd.html
“The goal of domain-driven design is to create
better software by focusing on a model of the
    domain rather than the technology.”
DDD LEADS TO MODEL-DRIVEN DESIGN
 Domain-Driven Design leads to Model-Driven
 Design since developers capture their knowledge
 of a domain in models
 In particular
   A model-driven design is software structured around
   a set o domain concepts
   E.g.: A model-driven design for a UI framework is
   one in which UI concepts, such as windows and
   menus
   Teams who embrace model-driven design are aware
   that a change to the code IS a change to the model
   (and vice versa)
MODEL-DRIVEN DESIGN BENEFITS DDD
 The model and its implementation shape each other
   The link between model and code makes the model
   relevant and ensures that the work spent on analysis is not
   wasted
 The model creates a language used by all team
 members
   The language spreads domain knowledge throughout a
   team
   It allows developers to speak to domain experts (e.g. users)
   without translation
 The model is distilled knowledge
   Analysis is hard; we need to capture the information we get
   from it
   The model is the team’s agreed-upon way of structuring
   domain knowledge and distinguishing the elements of most
   interest
TACKLING COMPLEXITY
 The heart of software is its ability to solve domain-related
 problems
 for its users
    Software functionality either solves a domain-related problem
    or performs a domain-related task
      All other features support these two goals
 When a domain is complex, it becomes difficult to
 accomplish this
    To be successful, developers must steep themselves in the
    domain
 Problem: Most developers are not interested in this!
    Domain work is messy and demands a lot of knowledge not
    necessarily related to computer science
    Developers enjoy quantifiable problems that exercise their
    technical skills!
    But, domain complexity has to be tackled head-on by
    developers or they risk irrelevance!
CRUNCHING KNOWLEDGE
 Domain modeling requires processing (crunching)
 knowledge
   In the same way that financial analysts crunch numbers
 While speaking with domain experts, a domain
 modeler will
   try one organizing idea (set of concepts) after another
   create models, try them out, reject some, transform others
 Success is achieved when the modeler has created a
 set of abstract concepts that makes sense of all the
 details provided by the domain experts
   Domain experts are a critical part of the process
   Without them, developers tend to create models with
   concepts that seem naive and shallow to domain experts
INGREDIENTS OF EFFECTIVE MODELING
 Bind the model and the implementation
   As a model is developed, create rapid prototypes that
   test the domain
   These prototypes contain primarily domain concepts
     no UI, no persistence, no infrastructure
 Develop a knowledge-rich model
   The objects of your model should have behavior and
   may follow rules
   The model should not be just a data schema (think
   class diagram) but should express behavior,
   constraints, etc. that help solve domain related
   problems
KNOWLEDGE-RICH DESIGN
 Models capture more information than just the
 “classes” of a domain
   it goes beyond the “find the nouns and verbs”
   heuristic of some object-oriented models


 In particular, models capture behavior, business
 activities, and business rules (policies,
 constraints, etc.)
EXAMPLE: MODELING BUSINESS RULES




 The association might look like this:
EXAMPLE: OVER BOOKING CARGO?
 A standard practice in the shipping industry is to
 accept more cargo than a particular ship can
 carry on voyage
   This is know as “overbooking” and is used because
   there are typically always last-minute cancellations
   One way of specifying the overbooking policy is via a
   percentage of the ship’s total capacity ~ 10%
EXAMPLE: HIDDEN KNOWLEDGE PROBLEM
 Overbooking policy is not reflected in our model
   The policy has been recorded in a requirements
   document and hidden away inside one method in our
   application
 Domain-Driven Design recommends making that
 knowledge a part of the model: change the model,
 change the code (and vice versa)
EXAMPLE: CONTINUED,
 Our code would now look like this:




 and the OverBookingPolicy class would have a method:
PROBLEM

 It is not practical for software developers to
 become domain experts, or for domain experts to
 become software developers.
 Both parties can easily become confused by the
 plethora of undefined terminology and acronyms.
 Solution: Ubiquitous Language.
UBIQUITOUS LANGUAGE
UBIQUITOUS LANGUAGE



   “A language structured around the
   domain model and used by all team
   members to connect all the activities
     of the team with the software.”
AGENDA

Why Domain-Driven Design?
Core Patterns
PROBLEM
 Domain-Driven Design is overkill.
   Very little domain logic.
   Mostly data entry / retrieval.
 Short deadline.
 Prototype or a “one off.”
 Low-level of modeling skill.
 Solution: Smart UI
SMART UI

 Put the business logic in the user interface.
 Create a separate user interface for every
 application function.
 Store all data in a shared relational database.
 Program in 4GL languages and use rapid
 prototyping tools; Java/C# is overkill.
PROBLEM

 Lots and lots of complicated domain logic.
 Long-lived project lifetime.
 Ambitious goals.
 High-level of modeling skill.
 Solution: (Domain) Model-Driven Design.
MODEL-DRIVEN DESIGN

 Uses a single model for both analysis (to understand
 the domain) and design (to implement the software).
 Requires an iterative development process and
 continuous refactoring.
 Developers are also modelers.

                                           This is hard.
ASIDE: THE MODEL DEBATE

      What is the relationship between the
      domain model and the source code?

 “Tightly relating the code to an underlying model
            gives the code meaning and
           makes the model relevant.”
PROBLEM

 There is too much crap in my domain logic.
 I wish I could pull all of this crap out so that the
 model is easier to see and change.
 Solution: Layered Architecture



                            Crap is a scientific term.
LAYERED ARCHITECTURE
USER INTERFACE LAYER

 Presents information to the user and interprets
 the user's commands.
APPLICATION LAYER

 Defines the application services: what the
 software actually does for the user.
 Orchestrates the domain objects to implement
 these application services.
 Has state reflecting the progress of a service call
 in execution.
 This layer is kept thin.
DOMAIN LAYER

 Represents concepts of the business, information
 about the business situation, and business rules.
 Maintains state reflecting the business situation.
 This layer is the heart of business software.
INFRASTRUCTURE LAYER

 Provides generic technical capabilities that
 support the higher layers.
   Message sending
   Persistence
   Rendering UI widgets
   Etc.
 This layer could be a library or a framework.
CORE OBJECTS

 Entities
 Value Objects
 Services
ENTITIES

“Objects which are not defined by their attributes,
             but rather by a thread of
     continuity and identity, which remains
       the same throughout the life of the
           software and even beyond.”
VALUE OBJECTS



     “Immutable objects that have no
    conceptual identity and whose only
   purpose is to describe some attribute
            of another object.”
SERVICES



   “Objects that have no state and whose
  only purpose is to represent an operation
           on the domain itself.”
PROBLEM

 The domain model is too big to understand.
 Solution: Module.
MODULE



 “A method of organizing related concepts
  and tasks in order to reduce complexity.”
DOMAIN OBJECT LIFE CYCLE
PROBLEM
 The object graph is biconnected.
   Every object has at least two references to other
   objects.
 Hard to enforce invariants.
 Hard to implement database transactions
 without touching every object in the system.
 Solution: Aggregate.
AGGREGATE
“A cluster of associated objects that are treated as a
          unit with regard to data changes.”

          All external access to the cluster
           is through a single root Entity.

        The root Entity enforces invariants
             among the other objects.
PROBLEM

 Is the root Entity responsible for creating the
 Aggregate?
 Observation: Creation code is different than run-
 time behavior code.
 Solution: Factory.
FACTORY

   “Encapsulates the knowledge necessary
        for complex object creation.”

Relevant patterns:
  Factory Method
  Abstract Factory
  Builder
PROBLEM
 How do you find an Aggregate?
   Navigate a network of object references.
     Increases coupling.
     Pollutes the domain objects with extra references.
   Pull data from the database.
     Should SQL go inside the domain objects?
     May violate data hiding principles.
 Solution: Repository.
REPOSITORY

       “Encapsulates database storage,
     retrieval, and search behavior which
       emulates a collection of objects.”

Looks like java.util.Collection.
Acts like a relational database.
THE END

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

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 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 Quickly
Domain Driven Design QuicklyDomain Driven Design Quickly
Domain Driven Design Quickly
 
Clean Architecture
Clean ArchitectureClean Architecture
Clean Architecture
 
Domain driven design and model driven development
Domain driven design and model driven developmentDomain driven design and model driven development
Domain driven design and model driven development
 
Domain Driven Design: Zero to Hero
Domain Driven Design: Zero to HeroDomain Driven Design: Zero to Hero
Domain Driven Design: Zero to Hero
 
Node.js BFFs: our way to better/micro frontends
Node.js BFFs: our way to better/micro frontendsNode.js BFFs: our way to better/micro frontends
Node.js BFFs: our way to better/micro frontends
 
Domain-Driven Design
Domain-Driven DesignDomain-Driven Design
Domain-Driven Design
 
Introduction to .net framework
Introduction to .net frameworkIntroduction to .net framework
Introduction to .net framework
 
Clean architecture
Clean architectureClean architecture
Clean architecture
 
Domain driven design
Domain driven designDomain driven design
Domain driven design
 
.Net Core
.Net Core.Net Core
.Net Core
 
Asp.net MVC training session
Asp.net MVC training sessionAsp.net MVC training session
Asp.net MVC training session
 
ASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with OverviewASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with Overview
 
Domain Driven Design Demonstrated
Domain Driven Design Demonstrated Domain Driven Design Demonstrated
Domain Driven Design Demonstrated
 
Domain Driven Design (Ultra) Distilled
Domain Driven Design (Ultra) DistilledDomain Driven Design (Ultra) Distilled
Domain Driven Design (Ultra) Distilled
 
D2 domain driven-design
D2 domain driven-designD2 domain driven-design
D2 domain driven-design
 
Microservices Architecture Part 2 Event Sourcing and Saga
Microservices Architecture Part 2 Event Sourcing and SagaMicroservices Architecture Part 2 Event Sourcing and Saga
Microservices Architecture Part 2 Event Sourcing and Saga
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
 

Andere mochten auch

Responsibility Driven Design
Responsibility Driven DesignResponsibility Driven Design
Responsibility Driven Design
Harsh Jegadeesan
 
Advanced API Design: how an awesome API can help you make friends, get rich, ...
Advanced API Design: how an awesome API can help you make friends, get rich, ...Advanced API Design: how an awesome API can help you make friends, get rich, ...
Advanced API Design: how an awesome API can help you make friends, get rich, ...
Jonathan Dahl
 

Andere mochten auch (20)

SOA India 2009 | SOA and Web Business Platforms
SOA India 2009 | SOA and Web Business PlatformsSOA India 2009 | SOA and Web Business Platforms
SOA India 2009 | SOA and Web Business Platforms
 
Responsibility Driven Design
Responsibility Driven DesignResponsibility Driven Design
Responsibility Driven Design
 
Web Business Platforms On The Cloud An Engineering Perspective
Web Business Platforms On The Cloud   An Engineering PerspectiveWeb Business Platforms On The Cloud   An Engineering Perspective
Web Business Platforms On The Cloud An Engineering Perspective
 
APIs make you mobile - Mobile World Congress 2017
APIs make you mobile - Mobile World Congress 2017APIs make you mobile - Mobile World Congress 2017
APIs make you mobile - Mobile World Congress 2017
 
Writing Effective Use Cases
 Writing Effective Use Cases Writing Effective Use Cases
Writing Effective Use Cases
 
Domain Modeling
Domain ModelingDomain Modeling
Domain Modeling
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Refactoring for Domain Driven Design
Refactoring for Domain Driven DesignRefactoring for Domain Driven Design
Refactoring for Domain Driven Design
 
Domain Driven Design 101
Domain Driven Design 101Domain Driven Design 101
Domain Driven Design 101
 
Modeling Software
Modeling SoftwareModeling Software
Modeling Software
 
Case Study Guidelines
Case Study GuidelinesCase Study Guidelines
Case Study Guidelines
 
Intelligent Business Operations for Utilities, powered by SAP HANA
Intelligent Business Operations for Utilities, powered by SAP HANAIntelligent Business Operations for Utilities, powered by SAP HANA
Intelligent Business Operations for Utilities, powered by SAP HANA
 
SAP API Business Hub - SAP Community Webinar
SAP API Business Hub - SAP Community Webinar SAP API Business Hub - SAP Community Webinar
SAP API Business Hub - SAP Community Webinar
 
SAP TechEd 2015 INT103 Enabling Digital Transformation with APIs and SAP API...
SAP TechEd  2015 INT103 Enabling Digital Transformation with APIs and SAP API...SAP TechEd  2015 INT103 Enabling Digital Transformation with APIs and SAP API...
SAP TechEd 2015 INT103 Enabling Digital Transformation with APIs and SAP API...
 
SAP API Business Hub
SAP API Business HubSAP API Business Hub
SAP API Business Hub
 
Apply Design Thinking to enable Digital Business Transformation with SAP In...
Apply Design Thinking to enable Digital Business Transformation with SAP In...Apply Design Thinking to enable Digital Business Transformation with SAP In...
Apply Design Thinking to enable Digital Business Transformation with SAP In...
 
User guide
User guideUser guide
User guide
 
Advanced API Design: how an awesome API can help you make friends, get rich, ...
Advanced API Design: how an awesome API can help you make friends, get rich, ...Advanced API Design: how an awesome API can help you make friends, get rich, ...
Advanced API Design: how an awesome API can help you make friends, get rich, ...
 
Applying Domain-Driven Design to APIs and Microservices - Austin API Meetup
Applying Domain-Driven Design to APIs and Microservices  - Austin API MeetupApplying Domain-Driven Design to APIs and Microservices  - Austin API Meetup
Applying Domain-Driven Design to APIs and Microservices - Austin API Meetup
 
jTransfo lightning talk
jTransfo lightning talkjTransfo lightning talk
jTransfo lightning talk
 

Ähnlich wie Domain Driven Design

04 designing architectures
04 designing architectures04 designing architectures
04 designing architectures
Majong DevJfu
 

Ähnlich wie Domain Driven Design (20)

Java TechTalk "Spring boot made life easier with Kubernetes and Microservices"
Java TechTalk "Spring boot made life easier with Kubernetes and Microservices"Java TechTalk "Spring boot made life easier with Kubernetes and Microservices"
Java TechTalk "Spring boot made life easier with Kubernetes and Microservices"
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Refreshing Domain Driven Design
Refreshing Domain Driven DesignRefreshing Domain Driven Design
Refreshing Domain Driven Design
 
Clean architecture with asp.net core
Clean architecture with asp.net coreClean architecture with asp.net core
Clean architecture with asp.net core
 
DDD
DDDDDD
DDD
 
Model Driven Architectures
Model Driven ArchitecturesModel Driven Architectures
Model Driven Architectures
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Sioux Hot-or-Not: Model Driven Software Development (Markus Voelter)
Sioux Hot-or-Not: Model Driven Software Development (Markus Voelter)Sioux Hot-or-Not: Model Driven Software Development (Markus Voelter)
Sioux Hot-or-Not: Model Driven Software Development (Markus Voelter)
 
Domain Driven Design: Made Easy employing Systemic Approach
Domain Driven Design: Made Easy employing Systemic ApproachDomain Driven Design: Made Easy employing Systemic Approach
Domain Driven Design: Made Easy employing Systemic Approach
 
Notes on software engineering
Notes on software engineeringNotes on software engineering
Notes on software engineering
 
DDD
DDDDDD
DDD
 
Software Architecture for Agile Development
Software Architecture for Agile DevelopmentSoftware Architecture for Agile Development
Software Architecture for Agile Development
 
A Lightweight MDD Process Applied in Small Projects
A Lightweight MDD Process Applied in Small ProjectsA Lightweight MDD Process Applied in Small Projects
A Lightweight MDD Process Applied in Small Projects
 
DDD eXchange
DDD eXchangeDDD eXchange
DDD eXchange
 
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)
 
04 designing architectures
04 designing architectures04 designing architectures
04 designing architectures
 
The Modern Software Architect
The Modern Software ArchitectThe Modern Software Architect
The Modern Software Architect
 
10 Things You Should Know About MDD
10 Things You Should Know About MDD10 Things You Should Know About MDD
10 Things You Should Know About MDD
 
Architecting for Change: An Agile Approach
Architecting for Change: An Agile ApproachArchitecting for Change: An Agile Approach
Architecting for Change: An Agile Approach
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 

Kürzlich hochgeladen

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Kürzlich hochgeladen (20)

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
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
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
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
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
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...
 

Domain Driven Design

  • 1. Harsh Jegadeesan’s CLASSROOM DOMAIN-DRIVEN DESIGN BITS Pilani Off-Campus Work-Integrated Learning Programmes
  • 2.
  • 4. ERIC EVANS SPEAKS Eric Evans, the author of Domain-Driven Design, has been programming and designing systems for 25 years He asserts that for most software projects, the primary focus should be on the domain and domain logic “Domain-driven design flows from the premise that the heart of software development is knowledge of the subject matter and finding useful ways of understanding that subject matter. The complexity that we should be tackling is the complexity of the domain itself -- not the technical architecture, not the user interface, not even specific features. This means designing everything around our understanding and conception of the most essential concepts of the business and justifying any other development by how it supports that core.” From http://domaindrivendesign.org/articles/blog/evans_eric_ddd_and_mdd.html
  • 5. “The goal of domain-driven design is to create better software by focusing on a model of the domain rather than the technology.”
  • 6. DDD LEADS TO MODEL-DRIVEN DESIGN Domain-Driven Design leads to Model-Driven Design since developers capture their knowledge of a domain in models In particular A model-driven design is software structured around a set o domain concepts E.g.: A model-driven design for a UI framework is one in which UI concepts, such as windows and menus Teams who embrace model-driven design are aware that a change to the code IS a change to the model (and vice versa)
  • 7. MODEL-DRIVEN DESIGN BENEFITS DDD The model and its implementation shape each other The link between model and code makes the model relevant and ensures that the work spent on analysis is not wasted The model creates a language used by all team members The language spreads domain knowledge throughout a team It allows developers to speak to domain experts (e.g. users) without translation The model is distilled knowledge Analysis is hard; we need to capture the information we get from it The model is the team’s agreed-upon way of structuring domain knowledge and distinguishing the elements of most interest
  • 8. TACKLING COMPLEXITY The heart of software is its ability to solve domain-related problems for its users Software functionality either solves a domain-related problem or performs a domain-related task All other features support these two goals When a domain is complex, it becomes difficult to accomplish this To be successful, developers must steep themselves in the domain Problem: Most developers are not interested in this! Domain work is messy and demands a lot of knowledge not necessarily related to computer science Developers enjoy quantifiable problems that exercise their technical skills! But, domain complexity has to be tackled head-on by developers or they risk irrelevance!
  • 9. CRUNCHING KNOWLEDGE Domain modeling requires processing (crunching) knowledge In the same way that financial analysts crunch numbers While speaking with domain experts, a domain modeler will try one organizing idea (set of concepts) after another create models, try them out, reject some, transform others Success is achieved when the modeler has created a set of abstract concepts that makes sense of all the details provided by the domain experts Domain experts are a critical part of the process Without them, developers tend to create models with concepts that seem naive and shallow to domain experts
  • 10. INGREDIENTS OF EFFECTIVE MODELING Bind the model and the implementation As a model is developed, create rapid prototypes that test the domain These prototypes contain primarily domain concepts no UI, no persistence, no infrastructure Develop a knowledge-rich model The objects of your model should have behavior and may follow rules The model should not be just a data schema (think class diagram) but should express behavior, constraints, etc. that help solve domain related problems
  • 11. KNOWLEDGE-RICH DESIGN Models capture more information than just the “classes” of a domain it goes beyond the “find the nouns and verbs” heuristic of some object-oriented models In particular, models capture behavior, business activities, and business rules (policies, constraints, etc.)
  • 12. EXAMPLE: MODELING BUSINESS RULES The association might look like this:
  • 13. EXAMPLE: OVER BOOKING CARGO? A standard practice in the shipping industry is to accept more cargo than a particular ship can carry on voyage This is know as “overbooking” and is used because there are typically always last-minute cancellations One way of specifying the overbooking policy is via a percentage of the ship’s total capacity ~ 10%
  • 14. EXAMPLE: HIDDEN KNOWLEDGE PROBLEM Overbooking policy is not reflected in our model The policy has been recorded in a requirements document and hidden away inside one method in our application Domain-Driven Design recommends making that knowledge a part of the model: change the model, change the code (and vice versa)
  • 15. EXAMPLE: CONTINUED, Our code would now look like this: and the OverBookingPolicy class would have a method:
  • 16. PROBLEM It is not practical for software developers to become domain experts, or for domain experts to become software developers. Both parties can easily become confused by the plethora of undefined terminology and acronyms. Solution: Ubiquitous Language.
  • 18. UBIQUITOUS LANGUAGE “A language structured around the domain model and used by all team members to connect all the activities of the team with the software.”
  • 19.
  • 21. PROBLEM Domain-Driven Design is overkill. Very little domain logic. Mostly data entry / retrieval. Short deadline. Prototype or a “one off.” Low-level of modeling skill. Solution: Smart UI
  • 22. SMART UI Put the business logic in the user interface. Create a separate user interface for every application function. Store all data in a shared relational database. Program in 4GL languages and use rapid prototyping tools; Java/C# is overkill.
  • 23. PROBLEM Lots and lots of complicated domain logic. Long-lived project lifetime. Ambitious goals. High-level of modeling skill. Solution: (Domain) Model-Driven Design.
  • 24. MODEL-DRIVEN DESIGN Uses a single model for both analysis (to understand the domain) and design (to implement the software). Requires an iterative development process and continuous refactoring. Developers are also modelers. This is hard.
  • 25. ASIDE: THE MODEL DEBATE What is the relationship between the domain model and the source code? “Tightly relating the code to an underlying model gives the code meaning and makes the model relevant.”
  • 26. PROBLEM There is too much crap in my domain logic. I wish I could pull all of this crap out so that the model is easier to see and change. Solution: Layered Architecture Crap is a scientific term.
  • 28. USER INTERFACE LAYER Presents information to the user and interprets the user's commands.
  • 29. APPLICATION LAYER Defines the application services: what the software actually does for the user. Orchestrates the domain objects to implement these application services. Has state reflecting the progress of a service call in execution. This layer is kept thin.
  • 30. DOMAIN LAYER Represents concepts of the business, information about the business situation, and business rules. Maintains state reflecting the business situation. This layer is the heart of business software.
  • 31. INFRASTRUCTURE LAYER Provides generic technical capabilities that support the higher layers. Message sending Persistence Rendering UI widgets Etc. This layer could be a library or a framework.
  • 32. CORE OBJECTS Entities Value Objects Services
  • 33. ENTITIES “Objects which are not defined by their attributes, but rather by a thread of continuity and identity, which remains the same throughout the life of the software and even beyond.”
  • 34. VALUE OBJECTS “Immutable objects that have no conceptual identity and whose only purpose is to describe some attribute of another object.”
  • 35. SERVICES “Objects that have no state and whose only purpose is to represent an operation on the domain itself.”
  • 36. PROBLEM The domain model is too big to understand. Solution: Module.
  • 37. MODULE “A method of organizing related concepts and tasks in order to reduce complexity.”
  • 39. PROBLEM The object graph is biconnected. Every object has at least two references to other objects. Hard to enforce invariants. Hard to implement database transactions without touching every object in the system. Solution: Aggregate.
  • 40. AGGREGATE “A cluster of associated objects that are treated as a unit with regard to data changes.” All external access to the cluster is through a single root Entity. The root Entity enforces invariants among the other objects.
  • 41. PROBLEM Is the root Entity responsible for creating the Aggregate? Observation: Creation code is different than run- time behavior code. Solution: Factory.
  • 42. FACTORY “Encapsulates the knowledge necessary for complex object creation.” Relevant patterns: Factory Method Abstract Factory Builder
  • 43. PROBLEM How do you find an Aggregate? Navigate a network of object references. Increases coupling. Pollutes the domain objects with extra references. Pull data from the database. Should SQL go inside the domain objects? May violate data hiding principles. Solution: Repository.
  • 44. REPOSITORY “Encapsulates database storage, retrieval, and search behavior which emulates a collection of objects.” Looks like java.util.Collection. Acts like a relational database.