SlideShare uma empresa Scribd logo
1 de 43
Domain Driven 
Design 
Using Laravel 
by 
Waqar Alamgir
Managing 
Complexity 
AKA Engineering
Functional 
Requirement
Lets Look at some Concepts 
1. MVC Design Pattern 
2. Entities 
3. Active Records
MVC Design 
Pattern
Entities 
“Many objects are found 
fundamentally by their 
attributes but rather by a 
thread of continuity and 
identity” – Eric Evans
Person 
Waqar Alamgir 
Age 26 
From Karachi 
Waqar Alamgir 
Age 26 
From Karachi
Active Records
Person 
Waqar Alamgir 
Age 26 
From Karachi 
Waqar Alamgir 
Age 26 
From Karachi 
ID NAME AGE LOCATION 
1 Waqar Alamgir 26 Karachi 
2 Waqar Alamgir 26 Karachi
Laravel Framewrok 
Laravel is a free, open source PHP web application 
framework, designed for the development of model–view– 
controller (MVC) web applications. Laravel is listed as 
the most popular PHP framework in 2013. 
Eloquent ORM (object-relational mapping) is an advanced 
PHP implementation of the active record pattern. 
Better Routing. 
Restful controllers provide an optional way for separating 
the logic behind serving HTTP GET and POST requests. 
Class auto loading. 
Migrations provide a version control system for database 
schemas.
That’s not DDD
Philosophy 
In building large scale web applications MVC 
seems like a good solution in the initial 
design phase. However after having built a 
few large apps that have multiple entry 
points (web, cli, api etc) you start to find 
that MVC breaks down. Start using Domain 
Driven Design.
A Common Application 
PRESENTATION LAYER 
Controllers 
Artisan Commands 
Queue Listeners 
SERVICE LAYER 
Sending Email 
Queuing up Jobs 
Repository Implementations 
COMMANDS / COMMAND BUS 
DOMAIN 
Entities 
Repository Interface
What is Command 
Meat of the application 
Controller 
Artisan Command 
Queue Worker 
Whatever
What is Command 
Meat of the application 
Commands 
i.e. Register Member 
Command
What is Command 
Meat of the application 
Commands 
i.e. Register Member 
Command
Advantages 
1. No business policy in your controller 
2. Your code shows intent 
3. A single dedicated flow per user case 
4. A single point of entry per user case 
5. Easy to see which use cased are implemented
Register Command 
class RegisterMemberCommand 
{ 
public $displayName; 
public $email; 
public $password; 
public function __construct($displayName , $email , 
$password) 
{ 
$this->displayName = $displayName; 
$this->email = $email; 
$this->password = $password; 
} 
}
Register Command 
class RegisterMemberCommand 
{ 
public $displayName; 
public $email; 
public $password; 
public function __construct($displayName , $email , 
$password) 
{ 
$this->displayName = $displayName; 
$this->email = $email; 
$this->password = $password; 
} 
}
The Final Destination 
Register Member 
Handler 
Register Member 
Command 
Meat of the application
The Final Destination 
Register Member 
Handler 
Register Member 
Command 
Meat of the application 
Command Bus
Implementing 
Command Bus
class ExecutionCommandBus implements CommandBus 
{ 
private $container; 
private $mapper; 
public function __construct(Container $container , Mapper 
$mapper) 
{ 
$this->container = $container; 
$this->mapper = $mapper; 
} 
public function execute($command) 
{ 
$this->getHandler($command)->handle($command); 
} 
public function getHandler($command) 
{ 
$class = $this->mapper- 
>getHandlerClassFor($command); 
return $this->container->make($class); 
} 
}
How Does The 
Mapper Know?
One Handle Per 
Command
Let’s Look at 
very basic 
Register Member 
Command 
*with out any sequence*
class RegisterMemberHandler implements Handler 
{ 
private $memberRepository; 
public function __construct(MemberRepository 
$memberRepository) 
{ 
$this->memberRepository = $memberRepository; 
} 
public function handle($command) 
{ 
$member = Member::register( 
$command->displayName, 
$command->email, 
$command->password 
); 
$this->memberRepository->save($member); 
} 
}
class Member extends Eloquent 
{ 
public static function register($displayName , $email , 
$password) 
{ 
$member = new static([ 
‘display_name’ => $displayName, 
‘email’ => $email, 
‘password’ => $password 
]); 
return $member; 
} 
}
Flow Review
Flow Review 
PRESENTATION 
LAYER 
Command 
SERVICE 
LAYER 
COMMAND BUS Command Handler 
DOMAIN 
Entities 
Repositories
Simple Sequence
Simple Sequence 
Member Registers 
Subscribe to Mail 
Chimp 
Send Welcome Email 
Queue up 7 Day Email
Domain Events 
Trigger 
Listeners 
Raise Event 
Typical PUB-SUB pattern 
Dispatch Event
A Common Application 
PRESENTATION LAYER 
Controllers 
Artisan Commands 
Queue Listeners 
SERVICE LAYER 
Sending Email 
Queuing up Jobs 
Repository Implementations 
COMMANDS / COMMAND BUS 
Event Dispatcher 
DOMAIN 
Entities 
Repository Interface 
Domain Events
Events/ Listener 
Breakdown 
Member Registers 
Subscribe to Mail 
Chimp 
Send Welcome Email 
Queue up 7 Day Email
class MemberRegistered 
{ 
public $member; 
public function __construct(Member $member) 
{ 
$this->member = $member; 
} 
} 
class SendWelcomeEmail implements Listener 
{ 
public function handle($event) 
{ 
Mailer ::Queue(…); 
} 
}
Throwing Domain 
Events
class EventGenerator 
{ 
protected $pendingEvents = []; 
public function raise($event) 
{ 
$this->pendingEvents = $event; 
} 
public function releaseEvents() 
{ 
$events = $this->pendingEvents; 
$this->pendingEvents = [] ; 
return $events; 
} 
}
class Member extends Eloquent 
{ 
use EventGenerator ; 
public static function register($displayName , $email , 
$password) 
{ 
$member = new static([ 
‘display_name’ => $displayName, 
‘email’ => $email, 
‘password’ => $password 
]); 
$member->raise(new MemberRegistered($member)) ; 
return $member; 
} 
}
Interface Dispatcher 
{ 
public function addListener($eventName , Listener 
$listener) ; 
public function dispatch($events) ; 
} 
// Register Listeners 
$dispatcher = new Dispatcher() ; 
$dispatcher-> addListener(‘MemberRegistered’ , new 
SubscribeToMailchimp) ; 
$dispatcher-> addListener(‘MemberRegistered’ , new 
SendWelcomeEmail) ; 
$dispatcher-> addListener(‘MemberRegistered’ , new 
SendOneWeekEmail) ;
class RegisterMemberHandler implements Handler 
{ 
private $memberRepository; 
private $dispatcher; 
public function __construct(MemberRepository 
$memberRepository , Dispatcher $dispatcher) 
{ 
$this->memberRepository = $memberRepository; 
$this-> dispatcher = $dispatcher ; 
} 
public function handle($command) 
{ 
$member = Member::register( 
$command->displayName, $command->email, 
$command->password 
); 
$this->memberRepository->save($member); 
$this->dispatcher->dispatch($member-> 
releaseEvents()) ; 
} 
}
More Information 
About DDD 
Domain-Driven Design: Tackling 
Complexity in the Heart of 
Software - Eric Evans 
Implementing Domain-Driven 
Design- Vaughn Vernon
Thank You! 
Have more questions? 
Email: walamgir@folio3.com 
Twitter: @wajrcs

Mais conteúdo relacionado

Mais procurados

Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...Edureka!
 
Powershell Training
Powershell TrainingPowershell Training
Powershell TrainingFahad Noaman
 
NGSI によるデータ・モデリング - FIWARE WednesdayWebinars
NGSI によるデータ・モデリング - FIWARE WednesdayWebinarsNGSI によるデータ・モデリング - FIWARE WednesdayWebinars
NGSI によるデータ・モデリング - FIWARE WednesdayWebinarsfisuda
 
JSUG 20141127 「Spring Bootを用いたドメイン駆動設計」
JSUG 20141127 「Spring Bootを用いたドメイン駆動設計」JSUG 20141127 「Spring Bootを用いたドメイン駆動設計」
JSUG 20141127 「Spring Bootを用いたドメイン駆動設計」Junichiro Kazama
 
Laravel Design Patterns
Laravel Design PatternsLaravel Design Patterns
Laravel Design PatternsBobby Bouwmann
 
Шаблоны проектирования в Magento
Шаблоны проектирования в MagentoШаблоны проектирования в Magento
Шаблоны проектирования в MagentoPavel Usachev
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC PresentationVolkan Uzun
 
Swagger / Quick Start Guide
Swagger / Quick Start GuideSwagger / Quick Start Guide
Swagger / Quick Start GuideAndrii Gakhov
 
Class 3 - PHP Functions
Class 3 - PHP FunctionsClass 3 - PHP Functions
Class 3 - PHP FunctionsAhmed Swilam
 
PDSを実現するにあたっての技術動向の紹介 (OAuth, OpenID Connect, UMAなど)
PDSを実現するにあたっての技術動向の紹介 (OAuth, OpenID Connect, UMAなど)PDSを実現するにあたっての技術動向の紹介 (OAuth, OpenID Connect, UMAなど)
PDSを実現するにあたっての技術動向の紹介 (OAuth, OpenID Connect, UMAなど)Tatsuo Kudo
 
Deep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UKDeep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UKJosé Paumard
 
Transactions and Concurrency Control Patterns
Transactions and Concurrency Control PatternsTransactions and Concurrency Control Patterns
Transactions and Concurrency Control PatternsJ On The Beach
 

Mais procurados (20)

Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...
 
Express js
Express jsExpress js
Express js
 
Powershell Training
Powershell TrainingPowershell Training
Powershell Training
 
Json web token
Json web tokenJson web token
Json web token
 
NGSI によるデータ・モデリング - FIWARE WednesdayWebinars
NGSI によるデータ・モデリング - FIWARE WednesdayWebinarsNGSI によるデータ・モデリング - FIWARE WednesdayWebinars
NGSI によるデータ・モデリング - FIWARE WednesdayWebinars
 
Kotlin
KotlinKotlin
Kotlin
 
JSUG 20141127 「Spring Bootを用いたドメイン駆動設計」
JSUG 20141127 「Spring Bootを用いたドメイン駆動設計」JSUG 20141127 「Spring Bootを用いたドメイン駆動設計」
JSUG 20141127 「Spring Bootを用いたドメイン駆動設計」
 
Logback
LogbackLogback
Logback
 
Presentation swagger
Presentation swaggerPresentation swagger
Presentation swagger
 
Laravel Design Patterns
Laravel Design PatternsLaravel Design Patterns
Laravel Design Patterns
 
Keycloakの動向
Keycloakの動向Keycloakの動向
Keycloakの動向
 
Шаблоны проектирования в Magento
Шаблоны проектирования в MagentoШаблоны проектирования в Magento
Шаблоны проектирования в Magento
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
 
Swagger / Quick Start Guide
Swagger / Quick Start GuideSwagger / Quick Start Guide
Swagger / Quick Start Guide
 
Class 3 - PHP Functions
Class 3 - PHP FunctionsClass 3 - PHP Functions
Class 3 - PHP Functions
 
Apache Axis2におけるXML署名検証不備
Apache Axis2におけるXML署名検証不備Apache Axis2におけるXML署名検証不備
Apache Axis2におけるXML署名検証不備
 
PDSを実現するにあたっての技術動向の紹介 (OAuth, OpenID Connect, UMAなど)
PDSを実現するにあたっての技術動向の紹介 (OAuth, OpenID Connect, UMAなど)PDSを実現するにあたっての技術動向の紹介 (OAuth, OpenID Connect, UMAなど)
PDSを実現するにあたっての技術動向の紹介 (OAuth, OpenID Connect, UMAなど)
 
SOLID && Magento2
SOLID && Magento2SOLID && Magento2
SOLID && Magento2
 
Deep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UKDeep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UK
 
Transactions and Concurrency Control Patterns
Transactions and Concurrency Control PatternsTransactions and Concurrency Control Patterns
Transactions and Concurrency Control Patterns
 

Destaque

Implementing DDD Concepts in PHP
Implementing DDD Concepts in PHPImplementing DDD Concepts in PHP
Implementing DDD Concepts in PHPSteve Rhoades
 
Onion Architecture
Onion ArchitectureOnion Architecture
Onion Architecturematthidinger
 
Domain Driven Design Through Onion Architecture
Domain Driven Design Through Onion ArchitectureDomain Driven Design Through Onion Architecture
Domain Driven Design Through Onion ArchitectureBoldRadius Solutions
 
Applying Domain-Driven Design to APIs and Microservices - Austin API Meetup
Applying Domain-Driven Design to APIs and Microservices  - Austin API MeetupApplying Domain-Driven Design to APIs and Microservices  - Austin API Meetup
Applying Domain-Driven Design to APIs and Microservices - Austin API MeetupLaunchAny
 
API Design Methodology - Mike Amundsen, Director of API Architecture, API Aca...
API Design Methodology - Mike Amundsen, Director of API Architecture, API Aca...API Design Methodology - Mike Amundsen, Director of API Architecture, API Aca...
API Design Methodology - Mike Amundsen, Director of API Architecture, API Aca...CA API Management
 
The Architecture of an API Platform
The Architecture of an API PlatformThe Architecture of an API Platform
The Architecture of an API PlatformJohannes Ridderstedt
 
Api architectures for the modern enterprise
Api architectures for the modern enterpriseApi architectures for the modern enterprise
Api architectures for the modern enterpriseCA API Management
 
Designing APIs and Microservices Using Domain-Driven Design
Designing APIs and Microservices Using Domain-Driven DesignDesigning APIs and Microservices Using Domain-Driven Design
Designing APIs and Microservices Using Domain-Driven DesignLaunchAny
 
Software Design Patterns in Laravel by Phill Sparks
Software Design Patterns in Laravel by Phill SparksSoftware Design Patterns in Laravel by Phill Sparks
Software Design Patterns in Laravel by Phill SparksPhill Sparks
 

Destaque (10)

Implementing DDD Concepts in PHP
Implementing DDD Concepts in PHPImplementing DDD Concepts in PHP
Implementing DDD Concepts in PHP
 
Onion Architecture
Onion ArchitectureOnion Architecture
Onion Architecture
 
Domain Driven Design Through Onion Architecture
Domain Driven Design Through Onion ArchitectureDomain Driven Design Through Onion Architecture
Domain Driven Design Through Onion Architecture
 
Applying Domain-Driven Design to APIs and Microservices - Austin API Meetup
Applying Domain-Driven Design to APIs and Microservices  - Austin API MeetupApplying Domain-Driven Design to APIs and Microservices  - Austin API Meetup
Applying Domain-Driven Design to APIs and Microservices - Austin API Meetup
 
API Design Methodology - Mike Amundsen, Director of API Architecture, API Aca...
API Design Methodology - Mike Amundsen, Director of API Architecture, API Aca...API Design Methodology - Mike Amundsen, Director of API Architecture, API Aca...
API Design Methodology - Mike Amundsen, Director of API Architecture, API Aca...
 
The Architecture of an API Platform
The Architecture of an API PlatformThe Architecture of an API Platform
The Architecture of an API Platform
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Api architectures for the modern enterprise
Api architectures for the modern enterpriseApi architectures for the modern enterprise
Api architectures for the modern enterprise
 
Designing APIs and Microservices Using Domain-Driven Design
Designing APIs and Microservices Using Domain-Driven DesignDesigning APIs and Microservices Using Domain-Driven Design
Designing APIs and Microservices Using Domain-Driven Design
 
Software Design Patterns in Laravel by Phill Sparks
Software Design Patterns in Laravel by Phill SparksSoftware Design Patterns in Laravel by Phill Sparks
Software Design Patterns in Laravel by Phill Sparks
 

Semelhante a Domain Driven Design using Laravel

Laravel for Web Artisans
Laravel for Web ArtisansLaravel for Web Artisans
Laravel for Web ArtisansRaf Kewl
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5Darren Craig
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For BeginnersJonathan Wage
 
Osiąganie mądrej architektury z Symfony2
Osiąganie mądrej architektury z Symfony2 Osiąganie mądrej architektury z Symfony2
Osiąganie mądrej architektury z Symfony2 3camp
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenchesLukas Smith
 
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...ZFConf Conference
 
The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016Kacper Gunia
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the TrenchesJonathan Wage
 
Decoupling with Design Patterns and Symfony2 DIC
Decoupling with Design Patterns and Symfony2 DICDecoupling with Design Patterns and Symfony2 DIC
Decoupling with Design Patterns and Symfony2 DICKonstantin Kudryashov
 
symfony on action - WebTech 207
symfony on action - WebTech 207symfony on action - WebTech 207
symfony on action - WebTech 207patter
 
Laravel 5 In Depth
Laravel 5 In DepthLaravel 5 In Depth
Laravel 5 In DepthKirk Bushell
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐいHisateru Tanaka
 
Domain-driven Design in PHP and Symfony - Drupal Camp Wroclaw!
Domain-driven Design in PHP and Symfony - Drupal Camp Wroclaw!Domain-driven Design in PHP and Symfony - Drupal Camp Wroclaw!
Domain-driven Design in PHP and Symfony - Drupal Camp Wroclaw!Kacper Gunia
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)arcware
 
Beyond symfony 1.2 (Symfony Camp 2008)
Beyond symfony 1.2 (Symfony Camp 2008)Beyond symfony 1.2 (Symfony Camp 2008)
Beyond symfony 1.2 (Symfony Camp 2008)Fabien Potencier
 
Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2Hugo Hamon
 

Semelhante a Domain Driven Design using Laravel (20)

Laravel for Web Artisans
Laravel for Web ArtisansLaravel for Web Artisans
Laravel for Web Artisans
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
 
Osiąganie mądrej architektury z Symfony2
Osiąganie mądrej architektury z Symfony2 Osiąganie mądrej architektury z Symfony2
Osiąganie mądrej architektury z Symfony2
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenches
 
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
 
The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the Trenches
 
Intro to Laravel 4
Intro to Laravel 4Intro to Laravel 4
Intro to Laravel 4
 
What is DDD and how could it help you
What is DDD and how could it help youWhat is DDD and how could it help you
What is DDD and how could it help you
 
Decoupling with Design Patterns and Symfony2 DIC
Decoupling with Design Patterns and Symfony2 DICDecoupling with Design Patterns and Symfony2 DIC
Decoupling with Design Patterns and Symfony2 DIC
 
symfony on action - WebTech 207
symfony on action - WebTech 207symfony on action - WebTech 207
symfony on action - WebTech 207
 
Laravel 5 In Depth
Laravel 5 In DepthLaravel 5 In Depth
Laravel 5 In Depth
 
The IoC Hydra
The IoC HydraThe IoC Hydra
The IoC Hydra
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
 
Domain-driven Design in PHP and Symfony - Drupal Camp Wroclaw!
Domain-driven Design in PHP and Symfony - Drupal Camp Wroclaw!Domain-driven Design in PHP and Symfony - Drupal Camp Wroclaw!
Domain-driven Design in PHP and Symfony - Drupal Camp Wroclaw!
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
 
Beyond symfony 1.2 (Symfony Camp 2008)
Beyond symfony 1.2 (Symfony Camp 2008)Beyond symfony 1.2 (Symfony Camp 2008)
Beyond symfony 1.2 (Symfony Camp 2008)
 
Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2
 

Mais de wajrcs

Mastering Kubernetes - Basics and Advanced Concepts using Example Project
Mastering Kubernetes - Basics and Advanced Concepts using Example ProjectMastering Kubernetes - Basics and Advanced Concepts using Example Project
Mastering Kubernetes - Basics and Advanced Concepts using Example Projectwajrcs
 
RDF Join Query Processing with Dual Simulation Pruning
RDF Join Query Processing with Dual Simulation PruningRDF Join Query Processing with Dual Simulation Pruning
RDF Join Query Processing with Dual Simulation Pruningwajrcs
 
A Fairness-aware Machine Learning Interface for End-to-end Discrimination Dis...
A Fairness-aware Machine Learning Interface for End-to-end Discrimination Dis...A Fairness-aware Machine Learning Interface for End-to-end Discrimination Dis...
A Fairness-aware Machine Learning Interface for End-to-end Discrimination Dis...wajrcs
 
Continuous Delivery - Automate & Build Better Software with Travis CI
Continuous Delivery - Automate & Build Better Software with Travis CIContinuous Delivery - Automate & Build Better Software with Travis CI
Continuous Delivery - Automate & Build Better Software with Travis CIwajrcs
 
Infrastructure Automation with Chef & Ansible
Infrastructure Automation with Chef & AnsibleInfrastructure Automation with Chef & Ansible
Infrastructure Automation with Chef & Ansiblewajrcs
 
Hacking hhvm
Hacking hhvmHacking hhvm
Hacking hhvmwajrcs
 

Mais de wajrcs (6)

Mastering Kubernetes - Basics and Advanced Concepts using Example Project
Mastering Kubernetes - Basics and Advanced Concepts using Example ProjectMastering Kubernetes - Basics and Advanced Concepts using Example Project
Mastering Kubernetes - Basics and Advanced Concepts using Example Project
 
RDF Join Query Processing with Dual Simulation Pruning
RDF Join Query Processing with Dual Simulation PruningRDF Join Query Processing with Dual Simulation Pruning
RDF Join Query Processing with Dual Simulation Pruning
 
A Fairness-aware Machine Learning Interface for End-to-end Discrimination Dis...
A Fairness-aware Machine Learning Interface for End-to-end Discrimination Dis...A Fairness-aware Machine Learning Interface for End-to-end Discrimination Dis...
A Fairness-aware Machine Learning Interface for End-to-end Discrimination Dis...
 
Continuous Delivery - Automate & Build Better Software with Travis CI
Continuous Delivery - Automate & Build Better Software with Travis CIContinuous Delivery - Automate & Build Better Software with Travis CI
Continuous Delivery - Automate & Build Better Software with Travis CI
 
Infrastructure Automation with Chef & Ansible
Infrastructure Automation with Chef & AnsibleInfrastructure Automation with Chef & Ansible
Infrastructure Automation with Chef & Ansible
 
Hacking hhvm
Hacking hhvmHacking hhvm
Hacking hhvm
 

Último

GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
Software Coding for software engineering
Software Coding for software engineeringSoftware Coding for software engineering
Software Coding for software engineeringssuserb3a23b
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 

Último (20)

GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
Software Coding for software engineering
Software Coding for software engineeringSoftware Coding for software engineering
Software Coding for software engineering
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 

Domain Driven Design using Laravel

  • 1. Domain Driven Design Using Laravel by Waqar Alamgir
  • 4. Lets Look at some Concepts 1. MVC Design Pattern 2. Entities 3. Active Records
  • 6. Entities “Many objects are found fundamentally by their attributes but rather by a thread of continuity and identity” – Eric Evans
  • 7. Person Waqar Alamgir Age 26 From Karachi Waqar Alamgir Age 26 From Karachi
  • 9. Person Waqar Alamgir Age 26 From Karachi Waqar Alamgir Age 26 From Karachi ID NAME AGE LOCATION 1 Waqar Alamgir 26 Karachi 2 Waqar Alamgir 26 Karachi
  • 10. Laravel Framewrok Laravel is a free, open source PHP web application framework, designed for the development of model–view– controller (MVC) web applications. Laravel is listed as the most popular PHP framework in 2013. Eloquent ORM (object-relational mapping) is an advanced PHP implementation of the active record pattern. Better Routing. Restful controllers provide an optional way for separating the logic behind serving HTTP GET and POST requests. Class auto loading. Migrations provide a version control system for database schemas.
  • 12. Philosophy In building large scale web applications MVC seems like a good solution in the initial design phase. However after having built a few large apps that have multiple entry points (web, cli, api etc) you start to find that MVC breaks down. Start using Domain Driven Design.
  • 13. A Common Application PRESENTATION LAYER Controllers Artisan Commands Queue Listeners SERVICE LAYER Sending Email Queuing up Jobs Repository Implementations COMMANDS / COMMAND BUS DOMAIN Entities Repository Interface
  • 14. What is Command Meat of the application Controller Artisan Command Queue Worker Whatever
  • 15. What is Command Meat of the application Commands i.e. Register Member Command
  • 16. What is Command Meat of the application Commands i.e. Register Member Command
  • 17. Advantages 1. No business policy in your controller 2. Your code shows intent 3. A single dedicated flow per user case 4. A single point of entry per user case 5. Easy to see which use cased are implemented
  • 18. Register Command class RegisterMemberCommand { public $displayName; public $email; public $password; public function __construct($displayName , $email , $password) { $this->displayName = $displayName; $this->email = $email; $this->password = $password; } }
  • 19. Register Command class RegisterMemberCommand { public $displayName; public $email; public $password; public function __construct($displayName , $email , $password) { $this->displayName = $displayName; $this->email = $email; $this->password = $password; } }
  • 20. The Final Destination Register Member Handler Register Member Command Meat of the application
  • 21. The Final Destination Register Member Handler Register Member Command Meat of the application Command Bus
  • 23. class ExecutionCommandBus implements CommandBus { private $container; private $mapper; public function __construct(Container $container , Mapper $mapper) { $this->container = $container; $this->mapper = $mapper; } public function execute($command) { $this->getHandler($command)->handle($command); } public function getHandler($command) { $class = $this->mapper- >getHandlerClassFor($command); return $this->container->make($class); } }
  • 24. How Does The Mapper Know?
  • 25. One Handle Per Command
  • 26. Let’s Look at very basic Register Member Command *with out any sequence*
  • 27. class RegisterMemberHandler implements Handler { private $memberRepository; public function __construct(MemberRepository $memberRepository) { $this->memberRepository = $memberRepository; } public function handle($command) { $member = Member::register( $command->displayName, $command->email, $command->password ); $this->memberRepository->save($member); } }
  • 28. class Member extends Eloquent { public static function register($displayName , $email , $password) { $member = new static([ ‘display_name’ => $displayName, ‘email’ => $email, ‘password’ => $password ]); return $member; } }
  • 30. Flow Review PRESENTATION LAYER Command SERVICE LAYER COMMAND BUS Command Handler DOMAIN Entities Repositories
  • 32. Simple Sequence Member Registers Subscribe to Mail Chimp Send Welcome Email Queue up 7 Day Email
  • 33. Domain Events Trigger Listeners Raise Event Typical PUB-SUB pattern Dispatch Event
  • 34. A Common Application PRESENTATION LAYER Controllers Artisan Commands Queue Listeners SERVICE LAYER Sending Email Queuing up Jobs Repository Implementations COMMANDS / COMMAND BUS Event Dispatcher DOMAIN Entities Repository Interface Domain Events
  • 35. Events/ Listener Breakdown Member Registers Subscribe to Mail Chimp Send Welcome Email Queue up 7 Day Email
  • 36. class MemberRegistered { public $member; public function __construct(Member $member) { $this->member = $member; } } class SendWelcomeEmail implements Listener { public function handle($event) { Mailer ::Queue(…); } }
  • 38. class EventGenerator { protected $pendingEvents = []; public function raise($event) { $this->pendingEvents = $event; } public function releaseEvents() { $events = $this->pendingEvents; $this->pendingEvents = [] ; return $events; } }
  • 39. class Member extends Eloquent { use EventGenerator ; public static function register($displayName , $email , $password) { $member = new static([ ‘display_name’ => $displayName, ‘email’ => $email, ‘password’ => $password ]); $member->raise(new MemberRegistered($member)) ; return $member; } }
  • 40. Interface Dispatcher { public function addListener($eventName , Listener $listener) ; public function dispatch($events) ; } // Register Listeners $dispatcher = new Dispatcher() ; $dispatcher-> addListener(‘MemberRegistered’ , new SubscribeToMailchimp) ; $dispatcher-> addListener(‘MemberRegistered’ , new SendWelcomeEmail) ; $dispatcher-> addListener(‘MemberRegistered’ , new SendOneWeekEmail) ;
  • 41. class RegisterMemberHandler implements Handler { private $memberRepository; private $dispatcher; public function __construct(MemberRepository $memberRepository , Dispatcher $dispatcher) { $this->memberRepository = $memberRepository; $this-> dispatcher = $dispatcher ; } public function handle($command) { $member = Member::register( $command->displayName, $command->email, $command->password ); $this->memberRepository->save($member); $this->dispatcher->dispatch($member-> releaseEvents()) ; } }
  • 42. More Information About DDD Domain-Driven Design: Tackling Complexity in the Heart of Software - Eric Evans Implementing Domain-Driven Design- Vaughn Vernon
  • 43. Thank You! Have more questions? Email: walamgir@folio3.com Twitter: @wajrcs