SlideShare a Scribd company logo
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

More Related Content

What's hot

Angular Data Binding
Angular Data BindingAngular Data Binding
Angular Data Binding
Jennifer Estrada
 
Angular 2.0 forms
Angular 2.0 formsAngular 2.0 forms
Angular 2.0 forms
Eyal Vardi
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
Jeevesh Pandey
 
Spring data presentation
Spring data presentationSpring data presentation
Spring data presentation
Oleksii Usyk
 
Asynchronous API in Java8, how to use CompletableFuture
Asynchronous API in Java8, how to use CompletableFutureAsynchronous API in Java8, how to use CompletableFuture
Asynchronous API in Java8, how to use CompletableFuture
José Paumard
 
Spring JDBCTemplate
Spring JDBCTemplateSpring JDBCTemplate
Spring JDBCTemplate
Guo Albert
 
Java 8 streams
Java 8 streamsJava 8 streams
Java 8 streams
Manav Prasad
 
Spring data jpa
Spring data jpaSpring data jpa
Spring data jpa
Jeevesh Pandey
 
Microservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring CloudMicroservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring Cloud
Eberhard Wolff
 
7 rules of simple and maintainable code
7 rules of simple and maintainable code7 rules of simple and maintainable code
7 rules of simple and maintainable code
Geshan Manandhar
 
PUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootPUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBoot
Josué Neis
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
Purbarun Chakrabarti
 
Spring Framework - AOP
Spring Framework - AOPSpring Framework - AOP
Spring Framework - AOP
Dzmitry Naskou
 
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Edureka!
 
Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming  Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming
WebStackAcademy
 
Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)
Gunith Devasurendra
 
JDBC Java Database Connectivity
JDBC Java Database ConnectivityJDBC Java Database Connectivity
JDBC Java Database Connectivity
Ranjan Kumar
 
Rxjs ppt
Rxjs pptRxjs ppt
Keeping a Secret with HashiCorp Vault
Keeping a Secret with HashiCorp VaultKeeping a Secret with HashiCorp Vault
Keeping a Secret with HashiCorp Vault
Mitchell Pronschinske
 
Java 8 presentation
Java 8 presentationJava 8 presentation
Java 8 presentation
Van Huong
 

What's hot (20)

Angular Data Binding
Angular Data BindingAngular Data Binding
Angular Data Binding
 
Angular 2.0 forms
Angular 2.0 formsAngular 2.0 forms
Angular 2.0 forms
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
 
Spring data presentation
Spring data presentationSpring data presentation
Spring data presentation
 
Asynchronous API in Java8, how to use CompletableFuture
Asynchronous API in Java8, how to use CompletableFutureAsynchronous API in Java8, how to use CompletableFuture
Asynchronous API in Java8, how to use CompletableFuture
 
Spring JDBCTemplate
Spring JDBCTemplateSpring JDBCTemplate
Spring JDBCTemplate
 
Java 8 streams
Java 8 streamsJava 8 streams
Java 8 streams
 
Spring data jpa
Spring data jpaSpring data jpa
Spring data jpa
 
Microservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring CloudMicroservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring Cloud
 
7 rules of simple and maintainable code
7 rules of simple and maintainable code7 rules of simple and maintainable code
7 rules of simple and maintainable code
 
PUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootPUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBoot
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
 
Spring Framework - AOP
Spring Framework - AOPSpring Framework - AOP
Spring Framework - AOP
 
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
 
Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming  Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming
 
Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)
 
JDBC Java Database Connectivity
JDBC Java Database ConnectivityJDBC Java Database Connectivity
JDBC Java Database Connectivity
 
Rxjs ppt
Rxjs pptRxjs ppt
Rxjs ppt
 
Keeping a Secret with HashiCorp Vault
Keeping a Secret with HashiCorp VaultKeeping a Secret with HashiCorp Vault
Keeping a Secret with HashiCorp Vault
 
Java 8 presentation
Java 8 presentationJava 8 presentation
Java 8 presentation
 

Viewers also liked

Implementing DDD Concepts in PHP
Implementing DDD Concepts in PHPImplementing DDD Concepts in PHP
Implementing DDD Concepts in PHP
Steve Rhoades
 
Onion Architecture
Onion ArchitectureOnion Architecture
Onion Architecture
matthidinger
 
Domain Driven Design Through Onion Architecture
Domain Driven Design Through Onion ArchitectureDomain Driven Design Through Onion Architecture
Domain Driven Design Through Onion Architecture
BoldRadius 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 Meetup
LaunchAny
 
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 Platform
Johannes Ridderstedt
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
Nikolay Vasilev
 
Api architectures for the modern enterprise
Api architectures for the modern enterpriseApi architectures for the modern enterprise
Api architectures for the modern enterprise
CA 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 Design
LaunchAny
 
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
Phill Sparks
 

Viewers also liked (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
 

Similar to Domain Driven Design using Laravel

Laravel for Web Artisans
Laravel for Web ArtisansLaravel for Web Artisans
Laravel for Web Artisans
Raf Kewl
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5
Darren Craig
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
Jonathan 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
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
Alena Holligan
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenches
Lukas 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 2016
Kacper Gunia
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the Trenches
Jonathan Wage
 
Intro to Laravel 4
Intro to Laravel 4Intro to Laravel 4
Intro to Laravel 4
Singapore PHP User Group
 
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
Luis Henrique Mulinari
 
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
Konstantin Kudryashov
 
symfony on action - WebTech 207
symfony on action - WebTech 207symfony on action - WebTech 207
symfony on action - WebTech 207
patter
 
Laravel 5 In Depth
Laravel 5 In DepthLaravel 5 In Depth
Laravel 5 In Depth
Kirk Bushell
 
The IoC Hydra
The IoC HydraThe IoC Hydra
The IoC Hydra
Kacper Gunia
 
関西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 Symfony2
Hugo Hamon
 

Similar to 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
 

More from 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 Project
wajrcs
 
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
wajrcs
 
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 CI
wajrcs
 
Infrastructure Automation with Chef & Ansible
Infrastructure Automation with Chef & AnsibleInfrastructure Automation with Chef & Ansible
Infrastructure Automation with Chef & Ansible
wajrcs
 
Hacking hhvm
Hacking hhvmHacking hhvm
Hacking hhvm
wajrcs
 

More from 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
 

Recently uploaded

Mobile App Development Company in Noida - Drona Infotech
Mobile App Development Company in Noida - Drona InfotechMobile App Development Company in Noida - Drona Infotech
Mobile App Development Company in Noida - Drona Infotech
Mobile App Development Company in Noida - Drona Infotech
 
High Girls Call Chennai 000XX00000 Provide Best And Top Girl Service And No1 ...
High Girls Call Chennai 000XX00000 Provide Best And Top Girl Service And No1 ...High Girls Call Chennai 000XX00000 Provide Best And Top Girl Service And No1 ...
High Girls Call Chennai 000XX00000 Provide Best And Top Girl Service And No1 ...
singhlata50dh
 
Mobile App Development Company in Noida - Drona Infotech.
Mobile App Development Company in Noida - Drona Infotech.Mobile App Development Company in Noida - Drona Infotech.
Mobile App Development Company in Noida - Drona Infotech.
Mobile App Development Company in Noida - Drona Infotech
 
Comprehensive Vulnerability Assessments Process _ Aardwolf Security.docx
Comprehensive Vulnerability Assessments Process _ Aardwolf Security.docxComprehensive Vulnerability Assessments Process _ Aardwolf Security.docx
Comprehensive Vulnerability Assessments Process _ Aardwolf Security.docx
Aardwolf Security
 
VVIP Girls Call Mumbai 9910780858 Provide Best And Top Girl Service And No1 i...
VVIP Girls Call Mumbai 9910780858 Provide Best And Top Girl Service And No1 i...VVIP Girls Call Mumbai 9910780858 Provide Best And Top Girl Service And No1 i...
VVIP Girls Call Mumbai 9910780858 Provide Best And Top Girl Service And No1 i...
jealousviolet
 
Top Chinese Government-backed APT Groups
Top Chinese Government-backed APT GroupsTop Chinese Government-backed APT Groups
Top Chinese Government-backed APT Groups
SOCRadar
 
The Ultimate Guide to Phone Spy Apps: Everything You Need to Know
The Ultimate Guide to Phone Spy Apps: Everything You Need to KnowThe Ultimate Guide to Phone Spy Apps: Everything You Need to Know
The Ultimate Guide to Phone Spy Apps: Everything You Need to Know
onemonitarsoftware
 
Maximizing Efficiency and Profitability: Optimizing Data Systems, Enhancing C...
Maximizing Efficiency and Profitability: Optimizing Data Systems, Enhancing C...Maximizing Efficiency and Profitability: Optimizing Data Systems, Enhancing C...
Maximizing Efficiency and Profitability: Optimizing Data Systems, Enhancing C...
OnePlan Solutions
 
Il Data Streaming per un’AI real-time di nuova generazione
Il Data Streaming per un’AI real-time di nuova generazioneIl Data Streaming per un’AI real-time di nuova generazione
Il Data Streaming per un’AI real-time di nuova generazione
confluent
 
Wired_2.0_Create_AmsterdamJUG_09072024.pptx
Wired_2.0_Create_AmsterdamJUG_09072024.pptxWired_2.0_Create_AmsterdamJUG_09072024.pptx
Wired_2.0_Create_AmsterdamJUG_09072024.pptx
SimonedeGijt
 
Cisco Live Announcements: New ThousandEyes Release Highlights - July 2024
Cisco Live Announcements: New ThousandEyes Release Highlights - July 2024Cisco Live Announcements: New ThousandEyes Release Highlights - July 2024
Cisco Live Announcements: New ThousandEyes Release Highlights - July 2024
ThousandEyes
 
BITCOIN HEIST RANSOMEWARE ATTACK PREDICTION
BITCOIN HEIST RANSOMEWARE ATTACK PREDICTIONBITCOIN HEIST RANSOMEWARE ATTACK PREDICTION
BITCOIN HEIST RANSOMEWARE ATTACK PREDICTION
ssuser2b426d1
 
Software development... for all? (keynote at ICSOFT'2024)
Software development... for all? (keynote at ICSOFT'2024)Software development... for all? (keynote at ICSOFT'2024)
Software development... for all? (keynote at ICSOFT'2024)
miso_uam
 
HIRE A HACKER FOR CHEATING HUSBAND/WIFE)
HIRE A HACKER FOR CHEATING HUSBAND/WIFE)HIRE A HACKER FOR CHEATING HUSBAND/WIFE)
HIRE A HACKER FOR CHEATING HUSBAND/WIFE)
josephinedrea942
 
ThaiPy meetup - Indexes and Django
ThaiPy meetup - Indexes and DjangoThaiPy meetup - Indexes and Django
ThaiPy meetup - Indexes and Django
akshesh doshi
 
Leading Project Management Tool Taskruop.pptx
Leading Project Management Tool Taskruop.pptxLeading Project Management Tool Taskruop.pptx
Leading Project Management Tool Taskruop.pptx
taskroupseo
 
NYGGS 360: A Complete ERP for Construction Innovation
NYGGS 360: A Complete ERP for Construction InnovationNYGGS 360: A Complete ERP for Construction Innovation
NYGGS 360: A Complete ERP for Construction Innovation
NYGGS Construction ERP Software
 
Girls Call Mysore 000XX00000 Provide Best And Top Girl Service And No1 in City
Girls Call Mysore 000XX00000 Provide Best And Top Girl Service And No1 in CityGirls Call Mysore 000XX00000 Provide Best And Top Girl Service And No1 in City
Girls Call Mysore 000XX00000 Provide Best And Top Girl Service And No1 in City
neshakor5152
 
Unleashing the Future: Building a Scalable and Up-to-Date GenAI Chatbot with ...
Unleashing the Future: Building a Scalable and Up-to-Date GenAI Chatbot with ...Unleashing the Future: Building a Scalable and Up-to-Date GenAI Chatbot with ...
Unleashing the Future: Building a Scalable and Up-to-Date GenAI Chatbot with ...
confluent
 
How To Fill Timesheet in TaskSprint: Quick Guide 2024
How To Fill Timesheet in TaskSprint: Quick Guide 2024How To Fill Timesheet in TaskSprint: Quick Guide 2024
How To Fill Timesheet in TaskSprint: Quick Guide 2024
TaskSprint | Employee Efficiency Software
 

Recently uploaded (20)

Mobile App Development Company in Noida - Drona Infotech
Mobile App Development Company in Noida - Drona InfotechMobile App Development Company in Noida - Drona Infotech
Mobile App Development Company in Noida - Drona Infotech
 
High Girls Call Chennai 000XX00000 Provide Best And Top Girl Service And No1 ...
High Girls Call Chennai 000XX00000 Provide Best And Top Girl Service And No1 ...High Girls Call Chennai 000XX00000 Provide Best And Top Girl Service And No1 ...
High Girls Call Chennai 000XX00000 Provide Best And Top Girl Service And No1 ...
 
Mobile App Development Company in Noida - Drona Infotech.
Mobile App Development Company in Noida - Drona Infotech.Mobile App Development Company in Noida - Drona Infotech.
Mobile App Development Company in Noida - Drona Infotech.
 
Comprehensive Vulnerability Assessments Process _ Aardwolf Security.docx
Comprehensive Vulnerability Assessments Process _ Aardwolf Security.docxComprehensive Vulnerability Assessments Process _ Aardwolf Security.docx
Comprehensive Vulnerability Assessments Process _ Aardwolf Security.docx
 
VVIP Girls Call Mumbai 9910780858 Provide Best And Top Girl Service And No1 i...
VVIP Girls Call Mumbai 9910780858 Provide Best And Top Girl Service And No1 i...VVIP Girls Call Mumbai 9910780858 Provide Best And Top Girl Service And No1 i...
VVIP Girls Call Mumbai 9910780858 Provide Best And Top Girl Service And No1 i...
 
Top Chinese Government-backed APT Groups
Top Chinese Government-backed APT GroupsTop Chinese Government-backed APT Groups
Top Chinese Government-backed APT Groups
 
The Ultimate Guide to Phone Spy Apps: Everything You Need to Know
The Ultimate Guide to Phone Spy Apps: Everything You Need to KnowThe Ultimate Guide to Phone Spy Apps: Everything You Need to Know
The Ultimate Guide to Phone Spy Apps: Everything You Need to Know
 
Maximizing Efficiency and Profitability: Optimizing Data Systems, Enhancing C...
Maximizing Efficiency and Profitability: Optimizing Data Systems, Enhancing C...Maximizing Efficiency and Profitability: Optimizing Data Systems, Enhancing C...
Maximizing Efficiency and Profitability: Optimizing Data Systems, Enhancing C...
 
Il Data Streaming per un’AI real-time di nuova generazione
Il Data Streaming per un’AI real-time di nuova generazioneIl Data Streaming per un’AI real-time di nuova generazione
Il Data Streaming per un’AI real-time di nuova generazione
 
Wired_2.0_Create_AmsterdamJUG_09072024.pptx
Wired_2.0_Create_AmsterdamJUG_09072024.pptxWired_2.0_Create_AmsterdamJUG_09072024.pptx
Wired_2.0_Create_AmsterdamJUG_09072024.pptx
 
Cisco Live Announcements: New ThousandEyes Release Highlights - July 2024
Cisco Live Announcements: New ThousandEyes Release Highlights - July 2024Cisco Live Announcements: New ThousandEyes Release Highlights - July 2024
Cisco Live Announcements: New ThousandEyes Release Highlights - July 2024
 
BITCOIN HEIST RANSOMEWARE ATTACK PREDICTION
BITCOIN HEIST RANSOMEWARE ATTACK PREDICTIONBITCOIN HEIST RANSOMEWARE ATTACK PREDICTION
BITCOIN HEIST RANSOMEWARE ATTACK PREDICTION
 
Software development... for all? (keynote at ICSOFT'2024)
Software development... for all? (keynote at ICSOFT'2024)Software development... for all? (keynote at ICSOFT'2024)
Software development... for all? (keynote at ICSOFT'2024)
 
HIRE A HACKER FOR CHEATING HUSBAND/WIFE)
HIRE A HACKER FOR CHEATING HUSBAND/WIFE)HIRE A HACKER FOR CHEATING HUSBAND/WIFE)
HIRE A HACKER FOR CHEATING HUSBAND/WIFE)
 
ThaiPy meetup - Indexes and Django
ThaiPy meetup - Indexes and DjangoThaiPy meetup - Indexes and Django
ThaiPy meetup - Indexes and Django
 
Leading Project Management Tool Taskruop.pptx
Leading Project Management Tool Taskruop.pptxLeading Project Management Tool Taskruop.pptx
Leading Project Management Tool Taskruop.pptx
 
NYGGS 360: A Complete ERP for Construction Innovation
NYGGS 360: A Complete ERP for Construction InnovationNYGGS 360: A Complete ERP for Construction Innovation
NYGGS 360: A Complete ERP for Construction Innovation
 
Girls Call Mysore 000XX00000 Provide Best And Top Girl Service And No1 in City
Girls Call Mysore 000XX00000 Provide Best And Top Girl Service And No1 in CityGirls Call Mysore 000XX00000 Provide Best And Top Girl Service And No1 in City
Girls Call Mysore 000XX00000 Provide Best And Top Girl Service And No1 in City
 
Unleashing the Future: Building a Scalable and Up-to-Date GenAI Chatbot with ...
Unleashing the Future: Building a Scalable and Up-to-Date GenAI Chatbot with ...Unleashing the Future: Building a Scalable and Up-to-Date GenAI Chatbot with ...
Unleashing the Future: Building a Scalable and Up-to-Date GenAI Chatbot with ...
 
How To Fill Timesheet in TaskSprint: Quick Guide 2024
How To Fill Timesheet in TaskSprint: Quick Guide 2024How To Fill Timesheet in TaskSprint: Quick Guide 2024
How To Fill Timesheet in TaskSprint: Quick Guide 2024
 

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