SlideShare ist ein Scribd-Unternehmen logo
1 von 53
Domain Driven Design
Ubiquitous Language 
UbiquitousLanguage@Fowler's blog
Ubiquitous Language 
That’s all there is to it
Ubiquitous Language 
That’s all there is to it 
Questions?
Client 
(Domain expert) 
Project Manager Developer 
We need to add a new 
security policy to our 
accounts. Our customers 
can’t have more than two 
active offers per billing term. 
We need to restrict 
promotions. A user cannot 
have more than two 
promotions per month. 
public function validate(User $user) 
{ 
// … other crazy validations 
if (count ($user->getPromotions()) > 2) 
throw new ValidationException( 
“User can’t have more than 2 
promotions per month” 
); 
// … continue with crazy validations 
}
Favor model language 
over translations
Client 
(Domain expert) 
Project Manager Developer 
We need to add a new 
security policy to our 
accounts. Our customers 
can’t have more than two 
active offers per billing term. 
public function validate(Account $account) 
{ 
// … other crazy validations 
if (! $account->satisfies( 
new ActiveOffersPerBillingTermSecurityPolicy 
)) 
throw new ValidationException( 
“Account did not satisfy the active offers 
security policy” 
); 
// … continue with crazy validations 
}
ActiveOffersPerBillingTerm 
SecurityPolicy 
… really? 
TOO MUCH CODE! 
I WON’T TYPE THAT!!!11
Semantics
Semantics 
ActiveOffersPerBillingTermSecurityPolicy means something 
in the MODEL LANGUAGE 
count($user->getPromotions()) > 2 
does not convey this knowledge
Semantics 
ActiveOffersPerBillingTermSecurityPolicy means something 
in the MODEL LANGUAGE 
count($user->getPromotions()) > 2 
does not convey this knowledge 
=> MAKE IMPLICIT BUSINESS RULES EXPLICIT
Favor model language 
over translations 
When a domain expert (client) feels something’s wrong with the model 
language, you’ll know something’s wrong with the domain model.
Client 
(Domain expert) 
Project Manager Developer 
When we talk about a billing 
term, we need to consider if 
the customer is billed on a 
monthly or yearly basis. 
| class ActiveOffersPerBillingTermSecurityPolicy 
| { 
| protected $maxOffers = 2; 
| 
| public function isSatisfiedBy(Account $account) 
| { 
| return count( 
- | $account->getMonthlyOffers() 
+ | $account->getOffersForBillingTerm() 
| ) < $this->maxOffers; 
| }
Domain Knowledge
Domain Knowledge 
Focus your efforts in building a clear domain, 
specific to your client’s needs
Knowledge crunching
Client 
(Domain expert) 
class LongOverdueCustomerContactCommand 
{ 
public function execute() 
{ 
$customers = Customer::where( 
‘account.balance’, ‘<’, 0 
)->get(); 
foreach ($customers as $customer) 
$this->sendRefinanceEmail($customer); 
} 
} 
Project Manager Developer 
We need to contact long 
overdue customers to 
refinance their debt.
Client 
(Domain expert) 
class LongOverdueCustomerContactCommand 
{ 
public function execute() 
{ 
$customers = Customer::where( 
‘account.balance’, ‘<’, 0 
)->get(); 
foreach ($customers as $customer) 
$this->sendRefinanceEmail($customer); 
} 
} 
Project Manager Developer 
We need to contact long 
overdue customers to 
refinance their debt.
Client 
(Domain expert) 
Project Manager Developer 
We need to contact long 
overdue customers to 
refinance their debt. 
What is the difference 
between a regular customer, 
an overdue customer and a 
long overdue customer?
Client 
(Domain expert) 
class CustomerRepository 
{ 
public function findOverdue() 
{ 
return Customer::where(‘account.balance’, ‘<’, 0) 
->get(); 
} 
public function findLongOverdue() 
{ 
// Write more complex query logic for this one... 
} 
} 
Project Manager Developer 
Overdue is straightforward, 
customers in debt right now. 
Long overdue customers are 
the ones that have been 
overdue over the last 3 
billing terms, at the end of 
each billing term.
Knowledge crunching 
Knowledge crunching deepens the domain 
model, and brings better understanding
But… How?
Domain-oriented 
Design Patterns
class AccountsController 
{ 
public function index() 
{ 
$accounts = Account::all(); 
return View::make(‘accounts.index’, [ 
‘accounts’ => $accounts 
]); 
} 
}
class AccountsController 
{ 
public function index() 
{ 
$accounts = Account::all(); 
return View::make(‘accounts.index’, [ 
‘accounts’ => $accounts 
]); 
} 
}
EvansClassification@Fowler's blog
Entities
Entities 
Objects with an identity 
Lifespan 
Unique criteria
ValueObjects
ValueObjects 
Defined by their attributes
Aggregates
Aggregates 
Cluster of domain objects 
Transactional coherence
Services
Services 
Domain coordinators 
Define actions
Repositories
Repositories 
Data access abstraction
Factories
Factories 
Object creation
Domain Events
Domain Events 
Objects that represent significant domain 
events
Domain-oriented 
Architecture
Layered Architecture
Layered Architecture
Hexagonal Architecture
Hexagonal Architecture
Domain-oriented 
Architecture 
Isolate your domain model from 
specific application needs: 
UI - Persistence - External Services - 
Application workflow - etc...
So… What’s the point?
It’s not about writing 
code
It’s not about writing 
code 
That’s the easy part… right?
It’s not about writing 
code 
It’s about understanding what needs to be 
solved before starting to code
Creating a language which 
makes conversations 
between domain experts and 
developers possible without 
misinterpretations
Creating a language which 
makes conversations 
between domain experts and 
developers possible without 
(so many) misinterpretations
● Eric Evans, “Domain-Driven Design: Tackling Complexity in the Heart of Software” 
● Vaughn Vernon, “Implementing Domain-Driven Design” 
● Martin Fowler, “Patterns of Enterprise Application Architecture” 
● dddcommunity.org | Domain Driven Design Community 
● -http://domainlanguage.com/ddd/reference/DDD_Reference_2011-01-31.pdf 
● -http://www.lmgtfy.com/?q=Domain+Driven+Design

Weitere ähnliche Inhalte

Ähnlich wie Introduction to Domain driven design (LaravelBA #5)

Airbnb - Braavos - Whered My Money Go
Airbnb - Braavos - Whered My Money GoAirbnb - Braavos - Whered My Money Go
Airbnb - Braavos - Whered My Money Go
Jiang-Ming Yang
 
Practical AngularJS
Practical AngularJSPractical AngularJS
Practical AngularJS
Wei Ru
 
Intro to AppExchange - Building Composite Apps
Intro to AppExchange - Building Composite AppsIntro to AppExchange - Building Composite Apps
Intro to AppExchange - Building Composite Apps
dreamforce2006
 
Navjot_Resume_2017_Latest
Navjot_Resume_2017_LatestNavjot_Resume_2017_Latest
Navjot_Resume_2017_Latest
Navjot Thakur
 
Agile methodologies based on BDD and CI by Nikolai Shevchenko
Agile methodologies based on BDD and CI by Nikolai ShevchenkoAgile methodologies based on BDD and CI by Nikolai Shevchenko
Agile methodologies based on BDD and CI by Nikolai Shevchenko
Moldova ICT Summit
 

Ähnlich wie Introduction to Domain driven design (LaravelBA #5) (20)

Week 8
Week 8Week 8
Week 8
 
Building and deploying microservices with event sourcing, CQRS and Docker (Me...
Building and deploying microservices with event sourcing, CQRS and Docker (Me...Building and deploying microservices with event sourcing, CQRS and Docker (Me...
Building and deploying microservices with event sourcing, CQRS and Docker (Me...
 
Qbesv5 Peer Presentation
Qbesv5 Peer PresentationQbesv5 Peer Presentation
Qbesv5 Peer Presentation
 
Airbnb - Braavos - Whered My Money Go
Airbnb - Braavos - Whered My Money GoAirbnb - Braavos - Whered My Money Go
Airbnb - Braavos - Whered My Money Go
 
Atl elevate programmatic developer slides
Atl elevate programmatic developer slidesAtl elevate programmatic developer slides
Atl elevate programmatic developer slides
 
Building microservices with Scala, functional domain models and Spring Boot (...
Building microservices with Scala, functional domain models and Spring Boot (...Building microservices with Scala, functional domain models and Spring Boot (...
Building microservices with Scala, functional domain models and Spring Boot (...
 
Detroit ELEVATE Track 2
Detroit ELEVATE Track 2Detroit ELEVATE Track 2
Detroit ELEVATE Track 2
 
AWS RoadShow Manchester Part 3 - Getting Started with AWS
AWS RoadShow Manchester Part 3 - Getting Started with AWSAWS RoadShow Manchester Part 3 - Getting Started with AWS
AWS RoadShow Manchester Part 3 - Getting Started with AWS
 
AWS RoadShow Dublin - Part 3 Getting Started with AWS
AWS RoadShow Dublin - Part 3 Getting Started with AWSAWS RoadShow Dublin - Part 3 Getting Started with AWS
AWS RoadShow Dublin - Part 3 Getting Started with AWS
 
AWS RoadShow Cambridge Part 4 - Getting Started with AWS
AWS RoadShow Cambridge Part 4 - Getting Started with AWSAWS RoadShow Cambridge Part 4 - Getting Started with AWS
AWS RoadShow Cambridge Part 4 - Getting Started with AWS
 
AWS RoadShow Bristol - Part 2 Getting Started with AWS
AWS RoadShow Bristol - Part 2 Getting Started with AWSAWS RoadShow Bristol - Part 2 Getting Started with AWS
AWS RoadShow Bristol - Part 2 Getting Started with AWS
 
Beyond MVC: from Model to Domain
Beyond MVC: from Model to DomainBeyond MVC: from Model to Domain
Beyond MVC: from Model to Domain
 
Practical AngularJS
Practical AngularJSPractical AngularJS
Practical AngularJS
 
Intro to AppExchange - Building Composite Apps
Intro to AppExchange - Building Composite AppsIntro to AppExchange - Building Composite Apps
Intro to AppExchange - Building Composite Apps
 
Navjot_Resume_2017_Latest
Navjot_Resume_2017_LatestNavjot_Resume_2017_Latest
Navjot_Resume_2017_Latest
 
Agile methodologies based on BDD and CI by Nikolai Shevchenko
Agile methodologies based on BDD and CI by Nikolai ShevchenkoAgile methodologies based on BDD and CI by Nikolai Shevchenko
Agile methodologies based on BDD and CI by Nikolai Shevchenko
 
ELEVATE Paris
ELEVATE ParisELEVATE Paris
ELEVATE Paris
 
Developing Next-Gen Enterprise Web Application
Developing Next-Gen Enterprise Web ApplicationDeveloping Next-Gen Enterprise Web Application
Developing Next-Gen Enterprise Web Application
 
Min-Maxing Software Costs - Laracon EU 2015
Min-Maxing Software Costs - Laracon EU 2015Min-Maxing Software Costs - Laracon EU 2015
Min-Maxing Software Costs - Laracon EU 2015
 
In Visual Studios C# console app using multiple class files create a.pdf
In Visual Studios C# console app using multiple class files create a.pdfIn Visual Studios C# console app using multiple class files create a.pdf
In Visual Studios C# console app using multiple class files create a.pdf
 

Kürzlich hochgeladen

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

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 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
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
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
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
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
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
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...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
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
 

Introduction to Domain driven design (LaravelBA #5)