SlideShare uma empresa Scribd logo
1 de 66
Domain Driven Design
DAY 1
Spoiler
• DDD is not for the perfectionist
Spoiler
• DDD is not for the perfectionist
Spoiler
• DDD is not for the perfectionist
• DDD is based on incremental changes (backed by TDD)
Spoiler
• DDD is not for the perfectionist
• DDD is based on incremental changes (backed by TDD)
• Those changes must be guided by business requirements
Delivering Software
• Focused on the final client
• Use the same language
• Iterate over the requirements
Delivering Software => Complexity
Delivering Software => Complexity
Delivering Software => Complexity
Technical Debt
Delivering Software => Complexity
Delivering Software => Complexity
Solution
• Focus on business direction
• Strategic DDD
• Keep software as small as possible
• Tactical DDD
Strategic DDD
•Business
Knowledge
Strategic DDD
• Business Knowledge
• Technology is not important if it doesn’t fulfill its objective
• Solve people problems
Strategic DDD
• Ubiquitous Language
• Bounded Context
• Context Mapping
Ubiquitous Language
• A set of business words
• Usually nouns and verbs
Agent
Property
Agency
Sell Buy
Ad Contact
Bounded Context
• A set of business words that are part of the Ubiquitous Language
for a specific business area
Agent
Property
Agency
Sell Buy
Ad Contact
Context Mapping
• A set of business words that are part of the Ubiquitous Language
whose purpose is to share knowledge between Bounded Contexts
Agent
Property
Agency
Sell Buy
Ad Contact
Context Mapping
• A set of business words that are part of the Ubiquitous Language
whose purpose is to share knowledge between Bounded Contexts
Agent
Property
Agency
Sell Buy
Ad Contact
Publish
Context Mapping
• A set of business words that are part of the Ubiquitous Language
whose purpose is to share knowledge between Bounded Contexts
Ad Opportunity
Contact Property
Search Demand
Exercise 1
• Define the Ubiquitous Language of Real Estate
• Define the Bounded Context of Management
• Define the Bounded Context of Classifieds
• Define Context Mappings between Management and Classifieds
Tactical DDD
• Based on Model Driven Design
• Design Data & Behavior as Models
• Based on Clean Architecture Concepts
• SOLID (again)
Back to the SOLID
• Single Responsibility
• Responsibility is not based on code, but
on abstractions
• A good abstraction is more valuable
than good code
• But a good abstraction leads to better
code!
• Component responsibility evolves
during the project lifecycle
Domain
Layer
Back to the SOLID
• Open Closed
• Open for lower level abstractions, closed
to different implementations
• Abstractions backed by other ones
Contact Contact
DAO
Contact Service
Business Logic
Persistence
Business Transaction
Back to the SOLID
• Liskov Substitution
• Ability to change different
implementations that expose the same
abstraction
• Constrained by invariants, pre-
conditions and post-conditions
Client Agent Agency
Contactable
Contact
Back to the SOLID
• Interface Segregation
• Expose different abstractions with the
same implementation
• Different abstractions != God object
Agent
Contactable Publisher
Back to the SOLID
• Dependency Inversion
• Abstractions are backed by other higher-
level abstractions
• An abstraction must not depend directly
or indirectly on itself
Controller
Application Service
Domain Services
Domains
LevelofAbstraction
Model Driven Design
• Responsibility is distributed in models
• Models are an accurate representation of a business concept for a
concrete problem
• Models are stateful and logic-aware
• Models are not necessarily objects (but usually defined with them)
Model Driven Design vs Service Driven Design
Model Driven Design
Model Driven Design (with ADT)
Model Driven Design
• Everything should be a model (no defined granularity)
• Model interaction backed by services
• Persistence outside models (DAO)
Exercise 2
• Model the following user stories:
• As an Agent, I want to create a Property
• As an Agent, I want to publish a Property as an Ad
• As a Client, I want to contact an Agent through an Ad
• As an Agent, I want to unpublish an Ad
• You can use Java, C# or JavaScript for this exercise
Model Driven Design
• Properties of a Model:
• A model has invariants
• A model has multiple contracts
• A model is able to interact with other models
• A model is composed by other models
Invariants
• An invariant is a set of constraints based on the system state
• You can’t create a user without an email
• You can’t create two properties with the same ID
• Invariant violations must fail-fast
• A model must not exist in the system if its invariants are not full-filled
Invariants
Contracts
• A contract is the definition of the abstraction that the model solves
• User is a contract
• Agent is a contract
• Both can be implemented by any model
Model Interaction
• A model needs to interact with the environment, so the system can
work
• A single model is completely useless
Model Composition
• Models are composed by other models
• Primitives are not models, but state
• int, String or long are not business objects
• Avoid Primitive Obsession
• A Garbage Collector isn´t a performance problem
Model Composition
Domain Driven Design
• Layered Architecture
• 3 essential Layers
• Application
• Domain
• Infrastructure
• Model-centric
• Focused on data integrity
Domain
Application
Infrastructure
Domain Driven Design - Domain Layer
• AKA Business Layer
• Split in two components
• Aggregate Roots
• Domain Services
• Depends on Infrastructure
Domain
Service
Aggregate
Root
Infrastructure
Service
Domain Driven Design – Aggregate Root
• An Aggregate Root is the central part of data and business integrity
• Handles interaction with other domain objects
• Handles invariants related with other domain objects
• Aggregate Roots are Entities
Domain Driven Design – Entity
• An Entity is a business object that can be referred unequivocally by
a unique identifier.
• Entities are property of a Bounded Context
• An entity can’t be found in more than one Bounded Context
• Entities are a composition of Value Objects and business logic
Domain Driven Design – Entity
Domain Driven Design – Value Object
• A Value Object is a representation of a business value with its own
invariants and business logic
• Value Objects do not have identity
• Value Objects can be composed
• Value Objects must be immutable and shareable
• Value Objects also represent Entities in other Bounded Contexts
Domain Driven Design – Value Object
Domain Driven Design – Domain Services
• Handle business transactions
• Backed by aggregate roots and infrastructure services
• Must be ACID
• Atomic
• Consistent
• Isolated
• Durable
Domain Driven Design – Domain Services
• As A Visitor, I want to login
• Must Exist
• Must not be banned
• Must have been
verified
Find Visitor By
Email
• Password must
match
• Update Login Date
Login
• Persists New User
Info
• Notifies other
system players
about the event
Save User
Domain Driven Design – Domain Services
• As A Visitor, I want to login
Domain
Service
Aggregate
Root
Infrastructure
Service
Domain Driven Design – Domain Services
• As A Visitor, I want to login
Domain Driven Design – Infrastructure Services
• Handle data persistence
• Handle data integrity
• Handle system-wide invariants
• Unique Keys
• Sub-domain Invariants
• Communicate with 3rd party systems (like Event Buses, APIs or DBs)
Domain Driven Design – Infrastructure Services
• They can be categorized in:
• Domain Wide Infrastructure Services
• Repositories (!= DAOs)
• Event Publishers
• Command Publishers
• System Wide Infrastructure Services
• Marshallers
• Controllers
• Views
Domain Driven Design – Infrastructure Services
• Domain Wide Infrastructure Services are very special
• Their contract are part of the domain, not part of the infrastructure
• Repository interfaces are on the ´domain´ package
• They understand part of the domain language but they are not part of the
domain
• They must validate some invariants
• The relationship is simple: the same the developers have with their Product Owners
Domain Driven Design – Application Services
• Handle domain-wide transactions
• Understand domain language
• Application transactions are
eventually consistent
ApplicationService
Domain Service
Domain Service
Domain Service
Domain Driven Design – Application Services
Domain Driven Design & Test Driven Development
Domain Driven Design & Test Driven Development
•Are Friends 
TDD
• A tool for designing software
• The developer designs software while acquiring business
knowledge
TDD Basics
Green
(Work)
Refactor
(Refine)
Red
(Design)
TDD for Domain Driven Design
Green
(Work)
Refactor
(Refine)
Red
(Design)
Optional
TDD for Domain Driven Design
• Red
• Design the simplest concept required for a functional prototype
• Less classes are best! Think always about abstractions
• Green
• Just make it work
• Refactor
• Do not refactor for better code
• Do not design if you don´t have enough business knowledge
• Design top-down if you are not sure about the functionality
TDD for Domain Driven Design
Red Green
Acquire
Business
Knowledge
Refactor
TDD – Refactor
• Refactor is not a tool for better code!
• Refactor is a tool for better abstractions!
• Do not refactor until you have better knowledge of the problem.
TDD – Refactor Direction
Application
Service
Domain
Service
Aggregate
Root
Abstraction Level
TDD – Refactor
• Do not forget component responsibility
• When refactoring, Domain Services must be always responsible of one
domain and ACID
• Do not break abstractions never
• If you need to break something, always break encapsulation instead of
abstractions
• Commits are a unit of time, software evolves, don’t try to create
perfect code

Mais conteúdo relacionado

Mais procurados

Domain Driven Design - DDDSydney 2011
Domain Driven Design - DDDSydney 2011Domain Driven Design - DDDSydney 2011
Domain Driven Design - DDDSydney 2011
thinkddd
 

Mais procurados (20)

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)
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
DDD Basics - Context mapping
DDD Basics - Context mappingDDD Basics - Context mapping
DDD Basics - Context mapping
 
Domain driven design
Domain driven designDomain driven design
Domain driven design
 
Modelling a complex domain with Domain-Driven Design
Modelling a complex domain with Domain-Driven DesignModelling a complex domain with Domain-Driven Design
Modelling a complex domain with Domain-Driven Design
 
Domain-Driven Design: The "What" and the "Why"
Domain-Driven Design: The "What" and the "Why"Domain-Driven Design: The "What" and the "Why"
Domain-Driven Design: The "What" and the "Why"
 
ZendCon 2011 UnCon Domain-Driven Design
ZendCon 2011 UnCon Domain-Driven DesignZendCon 2011 UnCon Domain-Driven Design
ZendCon 2011 UnCon Domain-Driven Design
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
SOAT Agile Day 2017 DDD
SOAT Agile Day 2017 DDDSOAT Agile Day 2017 DDD
SOAT Agile Day 2017 DDD
 
Domain Driven Design - Building Blocks
Domain Driven Design - Building BlocksDomain Driven Design - Building Blocks
Domain Driven Design - Building Blocks
 
CQRS recipes or how to cook your architecture
CQRS recipes or how to cook your architectureCQRS recipes or how to cook your architecture
CQRS recipes or how to cook your architecture
 
Domain Driven Design Communication Techniques
Domain Driven Design Communication TechniquesDomain Driven Design Communication Techniques
Domain Driven Design Communication Techniques
 
Domain Driven Design and Hexagonal Architecture
Domain Driven Design and Hexagonal ArchitectureDomain Driven Design and Hexagonal Architecture
Domain Driven Design and Hexagonal Architecture
 
Domain Driven Design Big Picture Strategic Patterns
Domain Driven Design Big Picture Strategic PatternsDomain Driven Design Big Picture Strategic Patterns
Domain Driven Design Big Picture Strategic Patterns
 
Domain Driven Design - Distillation - Chapter 15
Domain Driven Design - Distillation - Chapter 15Domain Driven Design - Distillation - Chapter 15
Domain Driven Design - Distillation - Chapter 15
 
How to Implement Domain Driven Design in Real Life SDLC
How to Implement Domain Driven Design  in Real Life SDLCHow to Implement Domain Driven Design  in Real Life SDLC
How to Implement Domain Driven Design in Real Life SDLC
 
DDD Strategic Design - Context Maps - Paulo Clavijo - April 2018
DDD Strategic Design - Context Maps - Paulo Clavijo - April 2018DDD Strategic Design - Context Maps - Paulo Clavijo - April 2018
DDD Strategic Design - Context Maps - Paulo Clavijo - April 2018
 
Cultivating Your Design Heuristics
Cultivating Your Design HeuristicsCultivating Your Design Heuristics
Cultivating Your Design Heuristics
 
Domain Driven Design Quickly
Domain Driven Design QuicklyDomain Driven Design Quickly
Domain Driven Design Quickly
 
Domain Driven Design - DDDSydney 2011
Domain Driven Design - DDDSydney 2011Domain Driven Design - DDDSydney 2011
Domain Driven Design - DDDSydney 2011
 

Semelhante a Schibsted Spain - Day 1 - DDD Course

Semelhante a Schibsted Spain - Day 1 - DDD Course (20)

Introduction to DDD
Introduction to DDDIntroduction to DDD
Introduction to DDD
 
Code & Cannoli - Domain Driven Design
Code & Cannoli - Domain Driven DesignCode & Cannoli - Domain Driven Design
Code & Cannoli - Domain Driven Design
 
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 Ruby Ways - JURNAL 05/10/2017
Domain Driven Design Ruby Ways -  JURNAL 05/10/2017Domain Driven Design Ruby Ways -  JURNAL 05/10/2017
Domain Driven Design Ruby Ways - JURNAL 05/10/2017
 
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
 
DDD with ASP.NET MVC - Steve Smith | FalafelCON 2014
DDD with ASP.NET MVC - Steve Smith | FalafelCON 2014DDD with ASP.NET MVC - Steve Smith | FalafelCON 2014
DDD with ASP.NET MVC - Steve Smith | FalafelCON 2014
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
2019-Nov: Domain Driven Design (DDD) and when not to use it
2019-Nov: Domain Driven Design (DDD) and when not to use it2019-Nov: Domain Driven Design (DDD) and when not to use it
2019-Nov: Domain Driven Design (DDD) and when not to use it
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Ten Advices for Architects
Ten Advices for ArchitectsTen Advices for Architects
Ten Advices for Architects
 
Software Engineering - Trends & Industry Practices
Software Engineering - Trends & Industry PracticesSoftware Engineering - Trends & Industry Practices
Software Engineering - Trends & Industry Practices
 
10 Hinweise für Architekten
10 Hinweise für Architekten10 Hinweise für Architekten
10 Hinweise für Architekten
 
Applying Domain-Driven Design to craft Rich Domain Models
Applying Domain-Driven Design to craft Rich Domain ModelsApplying Domain-Driven Design to craft Rich Domain Models
Applying Domain-Driven Design to craft Rich Domain Models
 
DOMAIN DRIVER DESIGN
DOMAIN DRIVER DESIGNDOMAIN DRIVER DESIGN
DOMAIN DRIVER DESIGN
 
Art of refactoring - Code Smells and Microservices Antipatterns
Art of refactoring - Code Smells and Microservices AntipatternsArt of refactoring - Code Smells and Microservices Antipatterns
Art of refactoring - Code Smells and Microservices Antipatterns
 
.NET Fest 2019. Halil Ibrahim Kalkan. Implementing Domain Driven Design
.NET Fest 2019. Halil Ibrahim Kalkan. Implementing Domain Driven Design.NET Fest 2019. Halil Ibrahim Kalkan. Implementing Domain Driven Design
.NET Fest 2019. Halil Ibrahim Kalkan. Implementing Domain Driven Design
 
Prashant technical practices-tdd for xebia event
Prashant   technical practices-tdd for xebia eventPrashant   technical practices-tdd for xebia event
Prashant technical practices-tdd for xebia event
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Solid principles of oo design
Solid principles of oo designSolid principles of oo design
Solid principles of oo design
 
From Rails legacy to DDD - Pivorak, Lviv
From Rails legacy to DDD - Pivorak, LvivFrom Rails legacy to DDD - Pivorak, Lviv
From Rails legacy to DDD - Pivorak, Lviv
 

Último

CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
anilsa9823
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 

Último (20)

Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 

Schibsted Spain - Day 1 - DDD Course

  • 2. Spoiler • DDD is not for the perfectionist
  • 3. Spoiler • DDD is not for the perfectionist
  • 4. Spoiler • DDD is not for the perfectionist • DDD is based on incremental changes (backed by TDD)
  • 5. Spoiler • DDD is not for the perfectionist • DDD is based on incremental changes (backed by TDD) • Those changes must be guided by business requirements
  • 6. Delivering Software • Focused on the final client • Use the same language • Iterate over the requirements
  • 9. Delivering Software => Complexity Technical Debt
  • 12. Solution • Focus on business direction • Strategic DDD • Keep software as small as possible • Tactical DDD
  • 14. Strategic DDD • Business Knowledge • Technology is not important if it doesn’t fulfill its objective • Solve people problems
  • 15. Strategic DDD • Ubiquitous Language • Bounded Context • Context Mapping
  • 16. Ubiquitous Language • A set of business words • Usually nouns and verbs Agent Property Agency Sell Buy Ad Contact
  • 17. Bounded Context • A set of business words that are part of the Ubiquitous Language for a specific business area Agent Property Agency Sell Buy Ad Contact
  • 18. Context Mapping • A set of business words that are part of the Ubiquitous Language whose purpose is to share knowledge between Bounded Contexts Agent Property Agency Sell Buy Ad Contact
  • 19. Context Mapping • A set of business words that are part of the Ubiquitous Language whose purpose is to share knowledge between Bounded Contexts Agent Property Agency Sell Buy Ad Contact Publish
  • 20. Context Mapping • A set of business words that are part of the Ubiquitous Language whose purpose is to share knowledge between Bounded Contexts Ad Opportunity Contact Property Search Demand
  • 21. Exercise 1 • Define the Ubiquitous Language of Real Estate • Define the Bounded Context of Management • Define the Bounded Context of Classifieds • Define Context Mappings between Management and Classifieds
  • 22. Tactical DDD • Based on Model Driven Design • Design Data & Behavior as Models • Based on Clean Architecture Concepts • SOLID (again)
  • 23. Back to the SOLID • Single Responsibility • Responsibility is not based on code, but on abstractions • A good abstraction is more valuable than good code • But a good abstraction leads to better code! • Component responsibility evolves during the project lifecycle Domain Layer
  • 24. Back to the SOLID • Open Closed • Open for lower level abstractions, closed to different implementations • Abstractions backed by other ones Contact Contact DAO Contact Service Business Logic Persistence Business Transaction
  • 25. Back to the SOLID • Liskov Substitution • Ability to change different implementations that expose the same abstraction • Constrained by invariants, pre- conditions and post-conditions Client Agent Agency Contactable Contact
  • 26. Back to the SOLID • Interface Segregation • Expose different abstractions with the same implementation • Different abstractions != God object Agent Contactable Publisher
  • 27. Back to the SOLID • Dependency Inversion • Abstractions are backed by other higher- level abstractions • An abstraction must not depend directly or indirectly on itself Controller Application Service Domain Services Domains LevelofAbstraction
  • 28. Model Driven Design • Responsibility is distributed in models • Models are an accurate representation of a business concept for a concrete problem • Models are stateful and logic-aware • Models are not necessarily objects (but usually defined with them)
  • 29. Model Driven Design vs Service Driven Design
  • 31. Model Driven Design (with ADT)
  • 32. Model Driven Design • Everything should be a model (no defined granularity) • Model interaction backed by services • Persistence outside models (DAO)
  • 33. Exercise 2 • Model the following user stories: • As an Agent, I want to create a Property • As an Agent, I want to publish a Property as an Ad • As a Client, I want to contact an Agent through an Ad • As an Agent, I want to unpublish an Ad • You can use Java, C# or JavaScript for this exercise
  • 34. Model Driven Design • Properties of a Model: • A model has invariants • A model has multiple contracts • A model is able to interact with other models • A model is composed by other models
  • 35. Invariants • An invariant is a set of constraints based on the system state • You can’t create a user without an email • You can’t create two properties with the same ID • Invariant violations must fail-fast • A model must not exist in the system if its invariants are not full-filled
  • 37. Contracts • A contract is the definition of the abstraction that the model solves • User is a contract • Agent is a contract • Both can be implemented by any model
  • 38. Model Interaction • A model needs to interact with the environment, so the system can work • A single model is completely useless
  • 39. Model Composition • Models are composed by other models • Primitives are not models, but state • int, String or long are not business objects • Avoid Primitive Obsession • A Garbage Collector isn´t a performance problem
  • 41. Domain Driven Design • Layered Architecture • 3 essential Layers • Application • Domain • Infrastructure • Model-centric • Focused on data integrity Domain Application Infrastructure
  • 42. Domain Driven Design - Domain Layer • AKA Business Layer • Split in two components • Aggregate Roots • Domain Services • Depends on Infrastructure Domain Service Aggregate Root Infrastructure Service
  • 43. Domain Driven Design – Aggregate Root • An Aggregate Root is the central part of data and business integrity • Handles interaction with other domain objects • Handles invariants related with other domain objects • Aggregate Roots are Entities
  • 44. Domain Driven Design – Entity • An Entity is a business object that can be referred unequivocally by a unique identifier. • Entities are property of a Bounded Context • An entity can’t be found in more than one Bounded Context • Entities are a composition of Value Objects and business logic
  • 45. Domain Driven Design – Entity
  • 46. Domain Driven Design – Value Object • A Value Object is a representation of a business value with its own invariants and business logic • Value Objects do not have identity • Value Objects can be composed • Value Objects must be immutable and shareable • Value Objects also represent Entities in other Bounded Contexts
  • 47. Domain Driven Design – Value Object
  • 48. Domain Driven Design – Domain Services • Handle business transactions • Backed by aggregate roots and infrastructure services • Must be ACID • Atomic • Consistent • Isolated • Durable
  • 49. Domain Driven Design – Domain Services • As A Visitor, I want to login • Must Exist • Must not be banned • Must have been verified Find Visitor By Email • Password must match • Update Login Date Login • Persists New User Info • Notifies other system players about the event Save User
  • 50. Domain Driven Design – Domain Services • As A Visitor, I want to login Domain Service Aggregate Root Infrastructure Service
  • 51. Domain Driven Design – Domain Services • As A Visitor, I want to login
  • 52. Domain Driven Design – Infrastructure Services • Handle data persistence • Handle data integrity • Handle system-wide invariants • Unique Keys • Sub-domain Invariants • Communicate with 3rd party systems (like Event Buses, APIs or DBs)
  • 53. Domain Driven Design – Infrastructure Services • They can be categorized in: • Domain Wide Infrastructure Services • Repositories (!= DAOs) • Event Publishers • Command Publishers • System Wide Infrastructure Services • Marshallers • Controllers • Views
  • 54. Domain Driven Design – Infrastructure Services • Domain Wide Infrastructure Services are very special • Their contract are part of the domain, not part of the infrastructure • Repository interfaces are on the ´domain´ package • They understand part of the domain language but they are not part of the domain • They must validate some invariants • The relationship is simple: the same the developers have with their Product Owners
  • 55. Domain Driven Design – Application Services • Handle domain-wide transactions • Understand domain language • Application transactions are eventually consistent ApplicationService Domain Service Domain Service Domain Service
  • 56. Domain Driven Design – Application Services
  • 57. Domain Driven Design & Test Driven Development
  • 58. Domain Driven Design & Test Driven Development •Are Friends 
  • 59. TDD • A tool for designing software • The developer designs software while acquiring business knowledge
  • 61. TDD for Domain Driven Design Green (Work) Refactor (Refine) Red (Design) Optional
  • 62. TDD for Domain Driven Design • Red • Design the simplest concept required for a functional prototype • Less classes are best! Think always about abstractions • Green • Just make it work • Refactor • Do not refactor for better code • Do not design if you don´t have enough business knowledge • Design top-down if you are not sure about the functionality
  • 63. TDD for Domain Driven Design Red Green Acquire Business Knowledge Refactor
  • 64. TDD – Refactor • Refactor is not a tool for better code! • Refactor is a tool for better abstractions! • Do not refactor until you have better knowledge of the problem.
  • 65. TDD – Refactor Direction Application Service Domain Service Aggregate Root Abstraction Level
  • 66. TDD – Refactor • Do not forget component responsibility • When refactoring, Domain Services must be always responsible of one domain and ACID • Do not break abstractions never • If you need to break something, always break encapsulation instead of abstractions • Commits are a unit of time, software evolves, don’t try to create perfect code