SlideShare uma empresa Scribd logo
1 de 47
Domain-Driven Design

     Dennis Traub
           @dtraub
     #devspace 2012-10-19
Domain
  A sphere of knowledge, influence, or activity.

  What an organization does and the world it does it in.
Model
  A system of abstractions that describes selected
  aspects of a Domain and can be used to solve
  problems related to that Domain.
don‘t model reality
we model useful abstractions of
reality
Ubiquitous Language
  A Language structured around the Domain Model
  and used by all team mebers.
Bounded Context
  An explicit Boundary within which a Domain
  Model exists.

  Inside the boundary all terms have specific meaning.
  They are part of the context‘s Ubiquitous Language.
BC Example: Online-Shop
  E-Commerce-System
  Inventory System
  Accounting
Subdomains
  The whole Domain of the organization is comprised
  of Subdomains.

  They focus on only one specific area of the whole
  business Domain.
Subdomain Example:
  Product Catalog
  Customer Management
  Orders
  Invoicing
  Inventory
  Shipping
don‘t build a model that
works for everyone
Core Domain
  The distinctive part of the Model, central to the user‘s
  goals, that differentiates the application and makes it
  valuable.

  The most important Subdomain.
Question # 1:

Which subdomain creates the greatest
competitive advantage?
Question # 2:

Which subdomain has the highest complexity?
we don‘t     use DDD when
there‘s no value in formalizing
the problem
we only use DDD in parts where
we get a competitive advantage
Aggregate
  A cluster of associated objects that are treated as a
  unit for the purpose of data changes.

  A set of consistency rules applies within the
  Aggregate‘s boundaries.
Exercise # 1: A simple Model
  We have Students, Courses, and Teachers
  A Student can take multiple Courses
  A Course can have multiple Students
  A Course is hosted by a Teacher
  A Teacher can host multiple Courses
public class Teacher
{
    public List<Course> Courses { get; private set; }
}


public class Course
{
    public Teacher Teacher { get; private set; }
    public List<Student> Students { get; private set; }
}

public class Student
{
    public List<Course> Courses { get; private set; }
}
Exercise # 2: Assign Teacher
  A Course ist hosted by a Teacher

  Constraint: A Teacher has a maximum number of
  students
public class Teacher
{
    public List<Course> Courses { get; private set; }
    public int MaximumNumberOfStudents { get; private set; }

    public void Assign(Course course) {
        if (course.Students.Count >= MaximumNumberOfStudents)
            throw ...
        this.Courses.Add(course);
        course.AssignTo(this);
    }
}

public class Course
{
    public Teacher Teacher { get; private set; }
    public void AssignTo(Teacher teacher) {
        this.Teachers.Add(teacher);
    }
}
public class Teacher
{
    public List<Course> Courses { get; private set; }
    public int MaximumNumberOfStudents { get; private set; }

    public void Assign(Course course) {
        if (course.Students.Count >= MaximumNumberOfStudents)
            throw ...
        this.Courses.Add(course);
        course.AssignTo(this);
    }
}

public class Course
{
    public Teacher Teacher { get; private set; }
    public void AssignTo(Teacher teacher) {
        this.Teachers.Add(teacher);
    }
}
Pattern # 1: Responsibility

  We don‘t know where to put things.

  Responsibilities must be clear.

  Have one way of doing something, not many.
public class Teacher
{
    public List<Course> Courses { get; private set; }
    public int MaximumNumberOfStudents { get; private set; }

    public void Assign(Course course) {
        if (course.Students.Count >= MaximumNumberOfStudents)
            throw ...
        this.Courses.Add(course);
        // course.AssignTo(this);
        course.Teacher = this;
    }
}

public class Course
{
    public Teacher Teacher { get; private set; }
    /* public void AssignTo(Teacher teacher) {
         this.Teachers.Add(teacher);
    } */
}
public class Teacher
{
    public List<Course> Courses { get; private set; }
    public int MaximumNumberOfStudents { get; private set; }

    public void Assign(Course course) {
        if (course.Students.Count >= MaximumNumberOfStudents)
            throw ...
        this.Courses.Add(course);
        // course.AssignTo(this);
        course.Teacher = this;
    }
}

public class Course
{
    public Teacher Teacher { get; private set; }
    /* public void AssignTo(Teacher teacher) {
         this.Teachers.Add(teacher);
    } */
}
Pattern # 2: Don‘t be stupid
  No rules on Teacher.Courses or Course.Teacher.

  We don‘t need the relationship.
don‘t model reality
public class Teacher
{
    public List<Course> Courses { get; private set; }
    public int MaximumNumberOfStudents { get; private set; }

    /* public void Assign(Course course) {
        if (course.Students.Count >= MaximumNumberOfStudents) throw ...
        this.Courses.Add(course);
        course.AssignTo(this);
    } */
}

public class Course
{
    // public Teacher Teacher { get; private set; }
    public int MaximumNumberOfStudents { get; private set; }

    public void AssignTo(Teacher teacher) {
        if (Students.Count >= teacher.MaximumNumberOfStudents)
            throw ...

        MaximumNumberOfStudents = teacher.MaximumNumberOfStudents;
    }
}
But what if ...
   What happens if the Teacher changes his/her
   maximum number of students?
New Use Case.
Ask the Domain Expert
Exercise # 3: Enroll Student
  A Student can enroll in a Course

  Constraint: A Student can only enroll in up to five
  Courses

  Constraint: A Student‘s Courses may not overlap
public class Course
{
    public int MaximumNumberOfStudents { get; private set; }
    public void Students { get; private set; }

    private void TryEnroll(Student student) {
        if (Students.Count() >= MaximumNumberOfStudents) throw ...
    }

    public void Enroll(Student student) {
        this.TryEnroll(student);
        student.TryEnroll(this);
        this.Students.Add(student);
        student.EnrollIn(this);
    }
}

public class Student
{
    public List<Course> Courses { get; private set; }

    public void TryEnrollIn(Course course) {
        foreach (var c in Courses) {
            if (c.OverlapsWith(course)) throw ...
        }
    }

    public void EnrollIn(Course course) {
        this.Courses.Add(course);
    }
}
public class Course
{
    public int MaximumNumberOfStudents { get; private set; }
    public void Students { get; private set; }

    private void TryEnroll(Student student) {
        if (Students.Count() >= MaximumNumberOfStudents) throw ...
    }

    public void Enroll(Student student) {
        this.TryEnroll(student);
        student.TryEnroll(this);
        this.Students.Add(student);
        student.EnrollIn(this);
    }
}

public class Student
{
    public List<Course> Courses { get; private set; }

    public void TryEnrollIn(Course course) {
        foreach (var c in Courses) {
            if (c.OverlapsWith(course)) throw ...
        }
    }

    public void EnrollIn(Course course) {
        this.Courses.Add(course);
    }
}
Pattern # 3: Capture Concepts
  We‘re missing an explicit concept:
  A Student has a Schedule
  The Schedule consists of Enrollments
  Constraint: Enrollments may not overlap
  Constraint: A Schedule may contain up to 5
  Enrollments
public class Course
{
    public int MaximumNumberOfStudents { get; private set; }
    public void Students { get; private set; }

    private void TryEnroll(Student student) {
        if (Students.Count() >= MaximumNumberOfStudents) throw ...
    }

    internal void Enroll(Student student) {
        // this.TryEnroll(student);
        // student.TryEnroll(this);
        this.Students.Add(student);
        // student.EnrollIn(this);
    }
}

public class Student
{
    public List<Course> Courses { get; private set; }
    public Schedule Schedule { get; private set; }

    public void EnrollIn(Course course) {
        var enrollment = course.CreateEnrollment(course);
        Schedule.TryAddEnrollment(enrollment);
        course.TryEnroll(this);
        Schedule.AddEnrollment(enrollment);
        course.Enroll(this);
    }
}
public class Course
{
    public int MaximumNumberOfStudents { get; private set; }
    // public void Students { get; private set; }
    public int NumberOfStudents { get; private set; }

    private void TryEnroll(Student student) {
        // if (Students.Count() >= MaximumNumberOfStudents) throw ...
        if (NumberOfStudents >= MaximumNumberOfStudents) throw ...
    }

    internal void Enroll(Student student) {
        this.NumberOfStudents++;
    }
}

public class Student
{
    public List<Course> Courses { get; private set; }
    public Schedule Schedule { get; private set; }

    public void EnrollIn(Course course) {
        var enrollment = course.CreateEnrollment(course);
        Schedule.TryAddEnrollment(enrollment);
        course.TryEnroll(this);
        Schedule.AddEnrollment(enrollment);
        course.Enroll(this);
    }
}
Aggregate
  A cluster of associated objects that are treated as a
  unit for the purpose of data changes.

  A set of consistency rules applies within the
  Aggregate‘s boundaries.
In other words:
  A Transaction should only affect one Aggregate.
What if ...
   ... they don‘t need to be done in one Transaction?

   ... we TryEnroll() but not Enroll()?
How big is the business impact?
Domain Events
  A Domain Event is a full-fledged part of the Domain
  Model, a representation of something that happened
  in the Domain.

  Something happened that Domain Experts care
  about, e.g. a Student enrolled in a Course.
public class Course
{
    public int MaximumNumberOfStudents { get; private set; }
    public int NumberOfStudents { get; private set; }

    private void TryEnroll(Student student) {
        if (NumberOfStudents >= MaximumNumberOfStudents) throw ...
    }

    /* public void Enroll(Student student) {
         this.NumberOfStudents++;
    } */

    public void Handle(StudentEnrolledInCourse event) {
        this.NumberOfStudents++;
    }
}

public class Student
{
    public List<Course> Courses { get; private set; }
    public Schedule Schedule { get; private set; }

    public void EnrollIn(Course course) {
        var enrollment = course.CreateEnrollment(course);
        Schedule.TryAddEnrollment(enrollment);
        course.TryEnroll(this);
        Schedule.AddEnrollment(enrollment);
        // course.Enroll(this);
        Bus.Publish(new StudentEnrolledInCourse( ... ));
    }
}
But, once again, what if ...
   ... the Student drops out of a Course?
New Use Case.
Ask the Domain Expert
1. don‘t be stupid

2. denormalize

3. break up consistencies
References & Further Reading:
  Inspiration for the exercises: The works of Greg Young

  Domain-Driven Design – Tackling Complexity in the Heart of Software,
  by Eric Evans, Addison-Wesley, 2004
  Implementing Domain-Driven Design by Vaughn Vernon, Addison-Wesley, 2012
  http://domaindrivendesign.org - DDD-Forum maintained by Eric Evans, et al.
  Effective Aggregate Design: bit.ly/ncCOTH
  Google Group: groups.google.com/forum/?fromgroups#!forum/dddcqrs
Dennis Traub

  @dtraub

 #devspace

Mais conteúdo relacionado

Mais procurados

서버리스 앱 배포 자동화 (김필중, AWS 솔루션즈 아키텍트) :: AWS DevDay2018
서버리스 앱 배포 자동화 (김필중, AWS 솔루션즈 아키텍트) :: AWS DevDay2018서버리스 앱 배포 자동화 (김필중, AWS 솔루션즈 아키텍트) :: AWS DevDay2018
서버리스 앱 배포 자동화 (김필중, AWS 솔루션즈 아키텍트) :: AWS DevDay2018Amazon Web Services Korea
 
CAF intro Hosters modern
CAF intro Hosters modernCAF intro Hosters modern
CAF intro Hosters modernssuserdb85d71
 
Amazon Relational Database Service (Amazon RDS)
Amazon Relational Database Service (Amazon RDS)Amazon Relational Database Service (Amazon RDS)
Amazon Relational Database Service (Amazon RDS)Amazon Web Services
 
Running Microsoft SharePoint On AWS - Smartronix and AWS - Webinar
Running Microsoft SharePoint On AWS - Smartronix and AWS - WebinarRunning Microsoft SharePoint On AWS - Smartronix and AWS - Webinar
Running Microsoft SharePoint On AWS - Smartronix and AWS - WebinarAmazon Web Services
 
AWS Black Belt Techシリーズ AWS Elastic Beanstalk
AWS Black Belt Techシリーズ  AWS  Elastic  BeanstalkAWS Black Belt Techシリーズ  AWS  Elastic  Beanstalk
AWS Black Belt Techシリーズ AWS Elastic BeanstalkAmazon Web Services Japan
 
NEW LAUNCH! AWS Shield—A Managed DDoS Protection Service
NEW LAUNCH! AWS Shield—A Managed DDoS Protection ServiceNEW LAUNCH! AWS Shield—A Managed DDoS Protection Service
NEW LAUNCH! AWS Shield—A Managed DDoS Protection ServiceAmazon Web Services
 
Azure Interview Questions And Answers | Azure Tutorial For Beginners | Azure ...
Azure Interview Questions And Answers | Azure Tutorial For Beginners | Azure ...Azure Interview Questions And Answers | Azure Tutorial For Beginners | Azure ...
Azure Interview Questions And Answers | Azure Tutorial For Beginners | Azure ...Edureka!
 
ニワトリでもわかるECS入門
ニワトリでもわかるECS入門ニワトリでもわかるECS入門
ニワトリでもわかるECS入門Yoshiki Kobayashi
 
Introduction to Spring Cloud
Introduction to Spring Cloud           Introduction to Spring Cloud
Introduction to Spring Cloud VMware Tanzu
 
[WhaTap DevOps Day] 세션 5 : 금융 Public 클라우드/ Devops 구축 여정
[WhaTap DevOps Day] 세션 5 : 금융 Public 클라우드/ Devops 구축 여정[WhaTap DevOps Day] 세션 5 : 금융 Public 클라우드/ Devops 구축 여정
[WhaTap DevOps Day] 세션 5 : 금융 Public 클라우드/ Devops 구축 여정WhaTap Labs
 
202205 AWS Black Belt Online Seminar Amazon VPC IP Address Manager (IPAM)
202205 AWS Black Belt Online Seminar Amazon VPC IP Address Manager (IPAM)202205 AWS Black Belt Online Seminar Amazon VPC IP Address Manager (IPAM)
202205 AWS Black Belt Online Seminar Amazon VPC IP Address Manager (IPAM)Amazon Web Services Japan
 
20190821 AWS Black Belt Online Seminar AWS AppSync
20190821 AWS Black Belt Online Seminar AWS AppSync20190821 AWS Black Belt Online Seminar AWS AppSync
20190821 AWS Black Belt Online Seminar AWS AppSyncAmazon Web Services Japan
 
[REPEAT] Microsoft Active Directory Deep Dive (WIN303-R) - AWS re:Invent 2018
[REPEAT] Microsoft Active Directory Deep Dive (WIN303-R) - AWS re:Invent 2018[REPEAT] Microsoft Active Directory Deep Dive (WIN303-R) - AWS re:Invent 2018
[REPEAT] Microsoft Active Directory Deep Dive (WIN303-R) - AWS re:Invent 2018Amazon Web Services
 
AWS Black Belt Techシリーズ Amazon WorkDocs / Amazon WorkMail
AWS Black Belt Techシリーズ Amazon WorkDocs / Amazon WorkMailAWS Black Belt Techシリーズ Amazon WorkDocs / Amazon WorkMail
AWS Black Belt Techシリーズ Amazon WorkDocs / Amazon WorkMailAmazon Web Services Japan
 
[20220126] JAWS-UG 2022初頭までに葬ったAWSアンチパターン大紹介
[20220126] JAWS-UG 2022初頭までに葬ったAWSアンチパターン大紹介[20220126] JAWS-UG 2022初頭までに葬ったAWSアンチパターン大紹介
[20220126] JAWS-UG 2022初頭までに葬ったAWSアンチパターン大紹介Amazon Web Services Japan
 

Mais procurados (20)

Serverless時代のJavaについて
Serverless時代のJavaについてServerless時代のJavaについて
Serverless時代のJavaについて
 
서버리스 앱 배포 자동화 (김필중, AWS 솔루션즈 아키텍트) :: AWS DevDay2018
서버리스 앱 배포 자동화 (김필중, AWS 솔루션즈 아키텍트) :: AWS DevDay2018서버리스 앱 배포 자동화 (김필중, AWS 솔루션즈 아키텍트) :: AWS DevDay2018
서버리스 앱 배포 자동화 (김필중, AWS 솔루션즈 아키텍트) :: AWS DevDay2018
 
From Monolith to Microservices
From Monolith to MicroservicesFrom Monolith to Microservices
From Monolith to Microservices
 
CAF intro Hosters modern
CAF intro Hosters modernCAF intro Hosters modern
CAF intro Hosters modern
 
Amazon Relational Database Service (Amazon RDS)
Amazon Relational Database Service (Amazon RDS)Amazon Relational Database Service (Amazon RDS)
Amazon Relational Database Service (Amazon RDS)
 
Running Microsoft SharePoint On AWS - Smartronix and AWS - Webinar
Running Microsoft SharePoint On AWS - Smartronix and AWS - WebinarRunning Microsoft SharePoint On AWS - Smartronix and AWS - Webinar
Running Microsoft SharePoint On AWS - Smartronix and AWS - Webinar
 
AWS Black Belt Techシリーズ AWS Elastic Beanstalk
AWS Black Belt Techシリーズ  AWS  Elastic  BeanstalkAWS Black Belt Techシリーズ  AWS  Elastic  Beanstalk
AWS Black Belt Techシリーズ AWS Elastic Beanstalk
 
Solid Principles
Solid PrinciplesSolid Principles
Solid Principles
 
NEW LAUNCH! AWS Shield—A Managed DDoS Protection Service
NEW LAUNCH! AWS Shield—A Managed DDoS Protection ServiceNEW LAUNCH! AWS Shield—A Managed DDoS Protection Service
NEW LAUNCH! AWS Shield—A Managed DDoS Protection Service
 
Azure Interview Questions And Answers | Azure Tutorial For Beginners | Azure ...
Azure Interview Questions And Answers | Azure Tutorial For Beginners | Azure ...Azure Interview Questions And Answers | Azure Tutorial For Beginners | Azure ...
Azure Interview Questions And Answers | Azure Tutorial For Beginners | Azure ...
 
私がなぜZscalerに?
私がなぜZscalerに?私がなぜZscalerに?
私がなぜZscalerに?
 
ニワトリでもわかるECS入門
ニワトリでもわかるECS入門ニワトリでもわかるECS入門
ニワトリでもわかるECS入門
 
Introduction to Spring Cloud
Introduction to Spring Cloud           Introduction to Spring Cloud
Introduction to Spring Cloud
 
[WhaTap DevOps Day] 세션 5 : 금융 Public 클라우드/ Devops 구축 여정
[WhaTap DevOps Day] 세션 5 : 금융 Public 클라우드/ Devops 구축 여정[WhaTap DevOps Day] 세션 5 : 금융 Public 클라우드/ Devops 구축 여정
[WhaTap DevOps Day] 세션 5 : 금융 Public 클라우드/ Devops 구축 여정
 
202205 AWS Black Belt Online Seminar Amazon VPC IP Address Manager (IPAM)
202205 AWS Black Belt Online Seminar Amazon VPC IP Address Manager (IPAM)202205 AWS Black Belt Online Seminar Amazon VPC IP Address Manager (IPAM)
202205 AWS Black Belt Online Seminar Amazon VPC IP Address Manager (IPAM)
 
20190821 AWS Black Belt Online Seminar AWS AppSync
20190821 AWS Black Belt Online Seminar AWS AppSync20190821 AWS Black Belt Online Seminar AWS AppSync
20190821 AWS Black Belt Online Seminar AWS AppSync
 
[REPEAT] Microsoft Active Directory Deep Dive (WIN303-R) - AWS re:Invent 2018
[REPEAT] Microsoft Active Directory Deep Dive (WIN303-R) - AWS re:Invent 2018[REPEAT] Microsoft Active Directory Deep Dive (WIN303-R) - AWS re:Invent 2018
[REPEAT] Microsoft Active Directory Deep Dive (WIN303-R) - AWS re:Invent 2018
 
AWS Black Belt Techシリーズ Amazon WorkDocs / Amazon WorkMail
AWS Black Belt Techシリーズ Amazon WorkDocs / Amazon WorkMailAWS Black Belt Techシリーズ Amazon WorkDocs / Amazon WorkMail
AWS Black Belt Techシリーズ Amazon WorkDocs / Amazon WorkMail
 
[20220126] JAWS-UG 2022初頭までに葬ったAWSアンチパターン大紹介
[20220126] JAWS-UG 2022初頭までに葬ったAWSアンチパターン大紹介[20220126] JAWS-UG 2022初頭までに葬ったAWSアンチパターン大紹介
[20220126] JAWS-UG 2022初頭までに葬ったAWSアンチパターン大紹介
 
AWS networking fundamentals
AWS networking fundamentalsAWS networking fundamentals
AWS networking fundamentals
 

Semelhante a DDD Modeling Workshop

Starting with Main.java, where I tested everythingimport College..pdf
Starting with Main.java, where I tested everythingimport College..pdfStarting with Main.java, where I tested everythingimport College..pdf
Starting with Main.java, where I tested everythingimport College..pdfaptind
 
import school.; import school.courses.;public class Main { p.pdf
import school.; import school.courses.;public class Main { p.pdfimport school.; import school.courses.;public class Main { p.pdf
import school.; import school.courses.;public class Main { p.pdfannaiwatertreatment
 
C# Delegates, Events, Lambda
C# Delegates, Events, LambdaC# Delegates, Events, Lambda
C# Delegates, Events, LambdaJussi Pohjolainen
 
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo....NET Conf UY
 
Assignment 7
Assignment 7Assignment 7
Assignment 7IIUM
 
C# Summer course - Lecture 4
C# Summer course - Lecture 4C# Summer course - Lecture 4
C# Summer course - Lecture 4mohamedsamyali
 
Refactoring - Mejorando el diseño del código existente
Refactoring - Mejorando el diseño del código existenteRefactoring - Mejorando el diseño del código existente
Refactoring - Mejorando el diseño del código existenteMariano Sánchez
 
A457405934_21789_26_2018_Inheritance.ppt
A457405934_21789_26_2018_Inheritance.pptA457405934_21789_26_2018_Inheritance.ppt
A457405934_21789_26_2018_Inheritance.pptRithwikRanjan
 
Cs141 mid termexam2_fall2017_v1.1_solution
Cs141 mid termexam2_fall2017_v1.1_solutionCs141 mid termexam2_fall2017_v1.1_solution
Cs141 mid termexam2_fall2017_v1.1_solutionFahadaio
 
Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)farhan amjad
 
classes & objects.ppt
classes & objects.pptclasses & objects.ppt
classes & objects.pptBArulmozhi
 
[PL] O klasycznej, programistycznej elegancji
[PL] O klasycznej, programistycznej elegancji[PL] O klasycznej, programistycznej elegancji
[PL] O klasycznej, programistycznej elegancjiJakub Marchwicki
 
Hello. Im currently working on the last section to my assignment a.pdf
Hello. Im currently working on the last section to my assignment a.pdfHello. Im currently working on the last section to my assignment a.pdf
Hello. Im currently working on the last section to my assignment a.pdfirshadkumar3
 
Effective java-3rd-edition-ch4
Effective java-3rd-edition-ch4Effective java-3rd-edition-ch4
Effective java-3rd-edition-ch4Matt
 

Semelhante a DDD Modeling Workshop (20)

Starting with Main.java, where I tested everythingimport College..pdf
Starting with Main.java, where I tested everythingimport College..pdfStarting with Main.java, where I tested everythingimport College..pdf
Starting with Main.java, where I tested everythingimport College..pdf
 
import school.; import school.courses.;public class Main { p.pdf
import school.; import school.courses.;public class Main { p.pdfimport school.; import school.courses.;public class Main { p.pdf
import school.; import school.courses.;public class Main { p.pdf
 
C# Delegates, Events, Lambda
C# Delegates, Events, LambdaC# Delegates, Events, Lambda
C# Delegates, Events, Lambda
 
Mapeamento uml java
Mapeamento uml javaMapeamento uml java
Mapeamento uml java
 
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
 
Jar chapter 5_part_i
Jar chapter 5_part_iJar chapter 5_part_i
Jar chapter 5_part_i
 
Assignment 7
Assignment 7Assignment 7
Assignment 7
 
C# Summer course - Lecture 4
C# Summer course - Lecture 4C# Summer course - Lecture 4
C# Summer course - Lecture 4
 
6 class design
6 class design6 class design
6 class design
 
Refactoring - Mejorando el diseño del código existente
Refactoring - Mejorando el diseño del código existenteRefactoring - Mejorando el diseño del código existente
Refactoring - Mejorando el diseño del código existente
 
A457405934_21789_26_2018_Inheritance.ppt
A457405934_21789_26_2018_Inheritance.pptA457405934_21789_26_2018_Inheritance.ppt
A457405934_21789_26_2018_Inheritance.ppt
 
Cs141 mid termexam2_fall2017_v1.1_solution
Cs141 mid termexam2_fall2017_v1.1_solutionCs141 mid termexam2_fall2017_v1.1_solution
Cs141 mid termexam2_fall2017_v1.1_solution
 
Core java oop
Core java oopCore java oop
Core java oop
 
Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)
 
Lecture 4 part 1.pdf
Lecture 4 part 1.pdfLecture 4 part 1.pdf
Lecture 4 part 1.pdf
 
classes & objects.ppt
classes & objects.pptclasses & objects.ppt
classes & objects.ppt
 
[PL] O klasycznej, programistycznej elegancji
[PL] O klasycznej, programistycznej elegancji[PL] O klasycznej, programistycznej elegancji
[PL] O klasycznej, programistycznej elegancji
 
Hello. Im currently working on the last section to my assignment a.pdf
Hello. Im currently working on the last section to my assignment a.pdfHello. Im currently working on the last section to my assignment a.pdf
Hello. Im currently working on the last section to my assignment a.pdf
 
Object oriented concepts
Object oriented conceptsObject oriented concepts
Object oriented concepts
 
Effective java-3rd-edition-ch4
Effective java-3rd-edition-ch4Effective java-3rd-edition-ch4
Effective java-3rd-edition-ch4
 

Mais de Dennis Traub

Application Integration Patterns (not only) for Microservices
Application Integration Patterns (not only) for MicroservicesApplication Integration Patterns (not only) for Microservices
Application Integration Patterns (not only) for MicroservicesDennis Traub
 
Serverless SecOps Automation on AWS at AWS UG Krakow, Poland
Serverless SecOps Automation on AWS at AWS UG Krakow, PolandServerless SecOps Automation on AWS at AWS UG Krakow, Poland
Serverless SecOps Automation on AWS at AWS UG Krakow, PolandDennis Traub
 
Serverless Security Automation on AWS - Hamburg AWS User Group
Serverless Security Automation on AWS - Hamburg AWS User GroupServerless Security Automation on AWS - Hamburg AWS User Group
Serverless Security Automation on AWS - Hamburg AWS User GroupDennis Traub
 
Cloud ist keine Strategie - Keynote des AWS Cloud Day, Solingen
Cloud ist keine Strategie - Keynote des AWS Cloud Day, SolingenCloud ist keine Strategie - Keynote des AWS Cloud Day, Solingen
Cloud ist keine Strategie - Keynote des AWS Cloud Day, SolingenDennis Traub
 
Cloud ist keine Strategie - AWS Tech Community Summit Cologne, 2017
Cloud ist keine Strategie - AWS Tech Community Summit Cologne, 2017Cloud ist keine Strategie - AWS Tech Community Summit Cologne, 2017
Cloud ist keine Strategie - AWS Tech Community Summit Cologne, 2017Dennis Traub
 
Taming the Monolith - Microservices Meetup Hamburg
Taming the Monolith - Microservices Meetup HamburgTaming the Monolith - Microservices Meetup Hamburg
Taming the Monolith - Microservices Meetup HamburgDennis Traub
 
Taming the Monolith
Taming the MonolithTaming the Monolith
Taming the MonolithDennis Traub
 
DDD / Microservices @ Trivento Spring Camp, Utrecht, 2015
DDD / Microservices @ Trivento Spring Camp, Utrecht, 2015DDD / Microservices @ Trivento Spring Camp, Utrecht, 2015
DDD / Microservices @ Trivento Spring Camp, Utrecht, 2015Dennis Traub
 
Strategic Appplication Development with Domain-Driven Design (DDD)
Strategic Appplication Development with Domain-Driven Design (DDD)Strategic Appplication Development with Domain-Driven Design (DDD)
Strategic Appplication Development with Domain-Driven Design (DDD)Dennis Traub
 
An Introduction to CQRS
An Introduction to CQRSAn Introduction to CQRS
An Introduction to CQRSDennis Traub
 
Strategischer Anwendungsentwurf mit Domain-Driven Design
Strategischer Anwendungsentwurf mit Domain-Driven DesignStrategischer Anwendungsentwurf mit Domain-Driven Design
Strategischer Anwendungsentwurf mit Domain-Driven DesignDennis Traub
 
CQRS-Einführung - Teil 2
CQRS-Einführung - Teil 2CQRS-Einführung - Teil 2
CQRS-Einführung - Teil 2Dennis Traub
 
CQRS - Eine Einführung - NOUG 2011
CQRS - Eine Einführung - NOUG 2011CQRS - Eine Einführung - NOUG 2011
CQRS - Eine Einführung - NOUG 2011Dennis Traub
 

Mais de Dennis Traub (14)

Application Integration Patterns (not only) for Microservices
Application Integration Patterns (not only) for MicroservicesApplication Integration Patterns (not only) for Microservices
Application Integration Patterns (not only) for Microservices
 
Serverless SecOps Automation on AWS at AWS UG Krakow, Poland
Serverless SecOps Automation on AWS at AWS UG Krakow, PolandServerless SecOps Automation on AWS at AWS UG Krakow, Poland
Serverless SecOps Automation on AWS at AWS UG Krakow, Poland
 
Serverless Security Automation on AWS - Hamburg AWS User Group
Serverless Security Automation on AWS - Hamburg AWS User GroupServerless Security Automation on AWS - Hamburg AWS User Group
Serverless Security Automation on AWS - Hamburg AWS User Group
 
Cloud ist keine Strategie - Keynote des AWS Cloud Day, Solingen
Cloud ist keine Strategie - Keynote des AWS Cloud Day, SolingenCloud ist keine Strategie - Keynote des AWS Cloud Day, Solingen
Cloud ist keine Strategie - Keynote des AWS Cloud Day, Solingen
 
Cloud ist keine Strategie - AWS Tech Community Summit Cologne, 2017
Cloud ist keine Strategie - AWS Tech Community Summit Cologne, 2017Cloud ist keine Strategie - AWS Tech Community Summit Cologne, 2017
Cloud ist keine Strategie - AWS Tech Community Summit Cologne, 2017
 
Taming the Monolith - Microservices Meetup Hamburg
Taming the Monolith - Microservices Meetup HamburgTaming the Monolith - Microservices Meetup Hamburg
Taming the Monolith - Microservices Meetup Hamburg
 
Taming the Monolith
Taming the MonolithTaming the Monolith
Taming the Monolith
 
DDD / Microservices @ Trivento Spring Camp, Utrecht, 2015
DDD / Microservices @ Trivento Spring Camp, Utrecht, 2015DDD / Microservices @ Trivento Spring Camp, Utrecht, 2015
DDD / Microservices @ Trivento Spring Camp, Utrecht, 2015
 
Strategic Appplication Development with Domain-Driven Design (DDD)
Strategic Appplication Development with Domain-Driven Design (DDD)Strategic Appplication Development with Domain-Driven Design (DDD)
Strategic Appplication Development with Domain-Driven Design (DDD)
 
An Introduction to CQRS
An Introduction to CQRSAn Introduction to CQRS
An Introduction to CQRS
 
From DDD to CQRS
From DDD to CQRSFrom DDD to CQRS
From DDD to CQRS
 
Strategischer Anwendungsentwurf mit Domain-Driven Design
Strategischer Anwendungsentwurf mit Domain-Driven DesignStrategischer Anwendungsentwurf mit Domain-Driven Design
Strategischer Anwendungsentwurf mit Domain-Driven Design
 
CQRS-Einführung - Teil 2
CQRS-Einführung - Teil 2CQRS-Einführung - Teil 2
CQRS-Einführung - Teil 2
 
CQRS - Eine Einführung - NOUG 2011
CQRS - Eine Einführung - NOUG 2011CQRS - Eine Einführung - NOUG 2011
CQRS - Eine Einführung - NOUG 2011
 

Último

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
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 WorkerThousandEyes
 
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.pdfsudhanshuwaghmare1
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
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 FMESafe Software
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 

Último (20)

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
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
 
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
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
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
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 

DDD Modeling Workshop

  • 1. Domain-Driven Design Dennis Traub @dtraub #devspace 2012-10-19
  • 2. Domain A sphere of knowledge, influence, or activity. What an organization does and the world it does it in.
  • 3. Model A system of abstractions that describes selected aspects of a Domain and can be used to solve problems related to that Domain.
  • 5. we model useful abstractions of reality
  • 6. Ubiquitous Language A Language structured around the Domain Model and used by all team mebers.
  • 7. Bounded Context An explicit Boundary within which a Domain Model exists. Inside the boundary all terms have specific meaning. They are part of the context‘s Ubiquitous Language.
  • 8. BC Example: Online-Shop E-Commerce-System Inventory System Accounting
  • 9. Subdomains The whole Domain of the organization is comprised of Subdomains. They focus on only one specific area of the whole business Domain.
  • 10. Subdomain Example: Product Catalog Customer Management Orders Invoicing Inventory Shipping
  • 11. don‘t build a model that works for everyone
  • 12. Core Domain The distinctive part of the Model, central to the user‘s goals, that differentiates the application and makes it valuable. The most important Subdomain.
  • 13. Question # 1: Which subdomain creates the greatest competitive advantage?
  • 14. Question # 2: Which subdomain has the highest complexity?
  • 15. we don‘t use DDD when there‘s no value in formalizing the problem
  • 16. we only use DDD in parts where we get a competitive advantage
  • 17. Aggregate A cluster of associated objects that are treated as a unit for the purpose of data changes. A set of consistency rules applies within the Aggregate‘s boundaries.
  • 18. Exercise # 1: A simple Model We have Students, Courses, and Teachers A Student can take multiple Courses A Course can have multiple Students A Course is hosted by a Teacher A Teacher can host multiple Courses
  • 19. public class Teacher { public List<Course> Courses { get; private set; } } public class Course { public Teacher Teacher { get; private set; } public List<Student> Students { get; private set; } } public class Student { public List<Course> Courses { get; private set; } }
  • 20. Exercise # 2: Assign Teacher A Course ist hosted by a Teacher Constraint: A Teacher has a maximum number of students
  • 21. public class Teacher { public List<Course> Courses { get; private set; } public int MaximumNumberOfStudents { get; private set; } public void Assign(Course course) { if (course.Students.Count >= MaximumNumberOfStudents) throw ... this.Courses.Add(course); course.AssignTo(this); } } public class Course { public Teacher Teacher { get; private set; } public void AssignTo(Teacher teacher) { this.Teachers.Add(teacher); } }
  • 22. public class Teacher { public List<Course> Courses { get; private set; } public int MaximumNumberOfStudents { get; private set; } public void Assign(Course course) { if (course.Students.Count >= MaximumNumberOfStudents) throw ... this.Courses.Add(course); course.AssignTo(this); } } public class Course { public Teacher Teacher { get; private set; } public void AssignTo(Teacher teacher) { this.Teachers.Add(teacher); } }
  • 23. Pattern # 1: Responsibility We don‘t know where to put things. Responsibilities must be clear. Have one way of doing something, not many.
  • 24. public class Teacher { public List<Course> Courses { get; private set; } public int MaximumNumberOfStudents { get; private set; } public void Assign(Course course) { if (course.Students.Count >= MaximumNumberOfStudents) throw ... this.Courses.Add(course); // course.AssignTo(this); course.Teacher = this; } } public class Course { public Teacher Teacher { get; private set; } /* public void AssignTo(Teacher teacher) { this.Teachers.Add(teacher); } */ }
  • 25. public class Teacher { public List<Course> Courses { get; private set; } public int MaximumNumberOfStudents { get; private set; } public void Assign(Course course) { if (course.Students.Count >= MaximumNumberOfStudents) throw ... this.Courses.Add(course); // course.AssignTo(this); course.Teacher = this; } } public class Course { public Teacher Teacher { get; private set; } /* public void AssignTo(Teacher teacher) { this.Teachers.Add(teacher); } */ }
  • 26. Pattern # 2: Don‘t be stupid No rules on Teacher.Courses or Course.Teacher. We don‘t need the relationship.
  • 28. public class Teacher { public List<Course> Courses { get; private set; } public int MaximumNumberOfStudents { get; private set; } /* public void Assign(Course course) { if (course.Students.Count >= MaximumNumberOfStudents) throw ... this.Courses.Add(course); course.AssignTo(this); } */ } public class Course { // public Teacher Teacher { get; private set; } public int MaximumNumberOfStudents { get; private set; } public void AssignTo(Teacher teacher) { if (Students.Count >= teacher.MaximumNumberOfStudents) throw ... MaximumNumberOfStudents = teacher.MaximumNumberOfStudents; } }
  • 29. But what if ... What happens if the Teacher changes his/her maximum number of students?
  • 30. New Use Case. Ask the Domain Expert
  • 31. Exercise # 3: Enroll Student A Student can enroll in a Course Constraint: A Student can only enroll in up to five Courses Constraint: A Student‘s Courses may not overlap
  • 32. public class Course { public int MaximumNumberOfStudents { get; private set; } public void Students { get; private set; } private void TryEnroll(Student student) { if (Students.Count() >= MaximumNumberOfStudents) throw ... } public void Enroll(Student student) { this.TryEnroll(student); student.TryEnroll(this); this.Students.Add(student); student.EnrollIn(this); } } public class Student { public List<Course> Courses { get; private set; } public void TryEnrollIn(Course course) { foreach (var c in Courses) { if (c.OverlapsWith(course)) throw ... } } public void EnrollIn(Course course) { this.Courses.Add(course); } }
  • 33. public class Course { public int MaximumNumberOfStudents { get; private set; } public void Students { get; private set; } private void TryEnroll(Student student) { if (Students.Count() >= MaximumNumberOfStudents) throw ... } public void Enroll(Student student) { this.TryEnroll(student); student.TryEnroll(this); this.Students.Add(student); student.EnrollIn(this); } } public class Student { public List<Course> Courses { get; private set; } public void TryEnrollIn(Course course) { foreach (var c in Courses) { if (c.OverlapsWith(course)) throw ... } } public void EnrollIn(Course course) { this.Courses.Add(course); } }
  • 34. Pattern # 3: Capture Concepts We‘re missing an explicit concept: A Student has a Schedule The Schedule consists of Enrollments Constraint: Enrollments may not overlap Constraint: A Schedule may contain up to 5 Enrollments
  • 35. public class Course { public int MaximumNumberOfStudents { get; private set; } public void Students { get; private set; } private void TryEnroll(Student student) { if (Students.Count() >= MaximumNumberOfStudents) throw ... } internal void Enroll(Student student) { // this.TryEnroll(student); // student.TryEnroll(this); this.Students.Add(student); // student.EnrollIn(this); } } public class Student { public List<Course> Courses { get; private set; } public Schedule Schedule { get; private set; } public void EnrollIn(Course course) { var enrollment = course.CreateEnrollment(course); Schedule.TryAddEnrollment(enrollment); course.TryEnroll(this); Schedule.AddEnrollment(enrollment); course.Enroll(this); } }
  • 36. public class Course { public int MaximumNumberOfStudents { get; private set; } // public void Students { get; private set; } public int NumberOfStudents { get; private set; } private void TryEnroll(Student student) { // if (Students.Count() >= MaximumNumberOfStudents) throw ... if (NumberOfStudents >= MaximumNumberOfStudents) throw ... } internal void Enroll(Student student) { this.NumberOfStudents++; } } public class Student { public List<Course> Courses { get; private set; } public Schedule Schedule { get; private set; } public void EnrollIn(Course course) { var enrollment = course.CreateEnrollment(course); Schedule.TryAddEnrollment(enrollment); course.TryEnroll(this); Schedule.AddEnrollment(enrollment); course.Enroll(this); } }
  • 37. Aggregate A cluster of associated objects that are treated as a unit for the purpose of data changes. A set of consistency rules applies within the Aggregate‘s boundaries.
  • 38. In other words: A Transaction should only affect one Aggregate.
  • 39. What if ... ... they don‘t need to be done in one Transaction? ... we TryEnroll() but not Enroll()?
  • 40. How big is the business impact?
  • 41. Domain Events A Domain Event is a full-fledged part of the Domain Model, a representation of something that happened in the Domain. Something happened that Domain Experts care about, e.g. a Student enrolled in a Course.
  • 42. public class Course { public int MaximumNumberOfStudents { get; private set; } public int NumberOfStudents { get; private set; } private void TryEnroll(Student student) { if (NumberOfStudents >= MaximumNumberOfStudents) throw ... } /* public void Enroll(Student student) { this.NumberOfStudents++; } */ public void Handle(StudentEnrolledInCourse event) { this.NumberOfStudents++; } } public class Student { public List<Course> Courses { get; private set; } public Schedule Schedule { get; private set; } public void EnrollIn(Course course) { var enrollment = course.CreateEnrollment(course); Schedule.TryAddEnrollment(enrollment); course.TryEnroll(this); Schedule.AddEnrollment(enrollment); // course.Enroll(this); Bus.Publish(new StudentEnrolledInCourse( ... )); } }
  • 43. But, once again, what if ... ... the Student drops out of a Course?
  • 44. New Use Case. Ask the Domain Expert
  • 45. 1. don‘t be stupid 2. denormalize 3. break up consistencies
  • 46. References & Further Reading: Inspiration for the exercises: The works of Greg Young Domain-Driven Design – Tackling Complexity in the Heart of Software, by Eric Evans, Addison-Wesley, 2004 Implementing Domain-Driven Design by Vaughn Vernon, Addison-Wesley, 2012 http://domaindrivendesign.org - DDD-Forum maintained by Eric Evans, et al. Effective Aggregate Design: bit.ly/ncCOTH Google Group: groups.google.com/forum/?fromgroups#!forum/dddcqrs
  • 47. Dennis Traub @dtraub #devspace