SlideShare a Scribd company logo
1 of 42
Domain Driven
Design
Using Laravel
by
Waqar Alamgir
@folio_3 www.folio3.com Copyright 2015
Managing
Complexity
AKA Engineering
@folio_3 www.folio3.com Copyright 2015
Functional
Requirement
@folio_3 www.folio3.com Copyright 2015
Lets Look at some Concepts
1. MVC Design Pattern
2. Entities
3. Active Records
@folio_3 www.folio3.com Copyright 2015
MVC Design
Pattern
@folio_3 www.folio3.com Copyright 2015
Entities
“Many objects are found
fundamentally by their
attributes but rather by a
thread of continuity and
identity” – Eric Evans
@folio_3 www.folio3.com Copyright 2015
Person
Waqar Alamgir
Age 26
From Karachi
Waqar Alamgir
Age 26
From Karachi
@folio_3 www.folio3.com Copyright 2015
Active Records
@folio_3 www.folio3.com Copyright 2015
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
@folio_3 www.folio3.com Copyright 2015
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.
Laravel Framewrok
@folio_3 Copyright 2015www.folio3.com
That’s not DDD
@folio_3 www.folio3.com Copyright 2015
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.
@folio_3 www.folio3.com Copyright 2015
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
@folio_3 www.folio3.com Copyright 2015
What is Command
Meat of the application
Controller
Artisan Command
Queue Worker
Whatever
@folio_3 www.folio3.com Copyright 2015
What is Command
Meat of the application
Commands
i.e. Register Member
Command
@folio_3 www.folio3.com Copyright 2015
What is Command
Meat of the application
Commands
i.e. Register Member
Command
@folio_3 www.folio3.com Copyright 2015
Advantages
1. No business policy in your controller
2. Your code shows intent
3. A single dedicated flow per use case
4. A single point of entry per use case
5. Easy to see which use cases are implemented
@folio_3 www.folio3.com Copyright 2015
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;
}
}
@folio_3 www.folio3.com Copyright 2015
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;
}
}
@folio_3 www.folio3.com Copyright 2015
The Final Destination
Register Member
Handler
Register Member
Command
Meat of the application
@folio_3 www.folio3.com Copyright 2015
The Final Destination
Register Member
Handler
Register Member
Command
Meat of the application
Command Bus
@folio_3 www.folio3.com Copyright 2015
Implementing
Command Bus
@folio_3 www.folio3.com Copyright 2015
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);
}}
@folio_3 www.folio3.com Copyright 2015
How Does The
Mapper Know?
@folio_3 www.folio3.com Copyright 2015
One Handle Per
Command
@folio_3 www.folio3.com Copyright 2015
Let’s Look at
very basic
Register Member
Command
*without any sequence*
@folio_3 www.folio3.com Copyright 2015
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);
}
}
@folio_3 www.folio3.com Copyright 2015
class Member extends Eloquent
{
public static function register($displayName , $email ,
$password)
{
$member = new static([
‘display_name’ => $displayName,
‘email’ => $email,
‘password’ => $password
]);
return $member;
}
}
@folio_3 www.folio3.com Copyright 2015
Flow Review
@folio_3 www.folio3.com Copyright 2015
Flow Review
PRESENTATION
LAYER
Command
SERVICE
LAYER
COMMAND BUS Command Handler
DOMAIN
Entities
Repositories
@folio_3 www.folio3.com Copyright 2015
Simple Sequence
@folio_3 www.folio3.com Copyright 2015
Simple Sequence
Member Registers
Subscribe to Mail
Chimp
Send Welcome Email
Queue up 7 Day Email
@folio_3 www.folio3.com Copyright 2015
Domain Events
Trigger
Listeners
Raise Event
Typical PUB-SUB pattern
Dispatch Event
@folio_3 www.folio3.com Copyright 2015
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
@folio_3 www.folio3.com Copyright 2015
Events/ Listener
Breakdown
Member
Registers
Subscribe to Mail
Chimp
Send Welcome Email
Queue up 7 Day
Email
@folio_3 www.folio3.com Copyright 2015
class MemberRegistered
{
public $member;
public function __construct(Member $member)
{
$this->member = $member;
}
}
class SendWelcomeEmail implements Listener
{
public function handle($event)
{
Mailer ::Queue(…);
}
}
@folio_3 www.folio3.com Copyright 2015
Throwing Domain
Events
@folio_3 www.folio3.com Copyright 2015
class EventGenerator
{
protected $pendingEvents = [];
public function raise($event)
{
$this->pendingEvents = $event;
}
public function releaseEvents()
{
$events = $this->pendingEvents;
$this->pendingEvents = [] ;
return $events;
}
}
@folio_3 www.folio3.com Copyright 2015
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;
}
}
@folio_3 www.folio3.com Copyright 2015
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) ;
@folio_3 www.folio3.com Copyright 2015
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()) ;
}
}
@folio_3 www.folio3.com Copyright 2015
More Information
About DDD
Domain-Driven Design: Tackling
Complexity in the Heart of
Software - Eric Evans
Implementing Domain-Driven
Design- Vaughn Vernon
@folio_3 www.folio3.com Copyright 2015

More Related Content

More from Folio3 Software

An Introduction to CSS Preprocessors (SASS & LESS)
An Introduction to CSS Preprocessors (SASS & LESS)An Introduction to CSS Preprocessors (SASS & LESS)
An Introduction to CSS Preprocessors (SASS & LESS)Folio3 Software
 
Introduction to SharePoint 2013
Introduction to SharePoint 2013Introduction to SharePoint 2013
Introduction to SharePoint 2013Folio3 Software
 
An Overview of Blackberry 10
An Overview of Blackberry 10An Overview of Blackberry 10
An Overview of Blackberry 10Folio3 Software
 
StackOverflow Architectural Overview
StackOverflow Architectural OverviewStackOverflow Architectural Overview
StackOverflow Architectural OverviewFolio3 Software
 
Enterprise Mobility - An Introduction
Enterprise Mobility - An IntroductionEnterprise Mobility - An Introduction
Enterprise Mobility - An IntroductionFolio3 Software
 
Distributed and Fault Tolerant Realtime Computation with Apache Storm, Apache...
Distributed and Fault Tolerant Realtime Computation with Apache Storm, Apache...Distributed and Fault Tolerant Realtime Computation with Apache Storm, Apache...
Distributed and Fault Tolerant Realtime Computation with Apache Storm, Apache...Folio3 Software
 
Introduction to Enterprise Service Bus
Introduction to Enterprise Service BusIntroduction to Enterprise Service Bus
Introduction to Enterprise Service BusFolio3 Software
 
NOSQL Database: Apache Cassandra
NOSQL Database: Apache CassandraNOSQL Database: Apache Cassandra
NOSQL Database: Apache CassandraFolio3 Software
 
Regular Expression in Action
Regular Expression in ActionRegular Expression in Action
Regular Expression in ActionFolio3 Software
 
HTTP Server Push Techniques
HTTP Server Push TechniquesHTTP Server Push Techniques
HTTP Server Push TechniquesFolio3 Software
 
Best Practices of Software Development
Best Practices of Software DevelopmentBest Practices of Software Development
Best Practices of Software DevelopmentFolio3 Software
 
Offline Data Access in Enterprise Mobility
Offline Data Access in Enterprise MobilityOffline Data Access in Enterprise Mobility
Offline Data Access in Enterprise MobilityFolio3 Software
 
Realtime and Synchronous Applications
Realtime and Synchronous ApplicationsRealtime and Synchronous Applications
Realtime and Synchronous ApplicationsFolio3 Software
 
Web Performance & Scalability Tools
Web Performance & Scalability ToolsWeb Performance & Scalability Tools
Web Performance & Scalability ToolsFolio3 Software
 
Andriod - Technical Review
Andriod - Technical ReviewAndriod - Technical Review
Andriod - Technical ReviewFolio3 Software
 
Web Application Security - Folio3
Web Application Security - Folio3Web Application Security - Folio3
Web Application Security - Folio3Folio3 Software
 
Dimensional Modelling - Basic Concept
Dimensional Modelling - Basic ConceptDimensional Modelling - Basic Concept
Dimensional Modelling - Basic ConceptFolio3 Software
 
NetSuite Integration Solutions - Folio3
NetSuite Integration Solutions - Folio3NetSuite Integration Solutions - Folio3
NetSuite Integration Solutions - Folio3Folio3 Software
 

More from Folio3 Software (20)

An Introduction to CSS Preprocessors (SASS & LESS)
An Introduction to CSS Preprocessors (SASS & LESS)An Introduction to CSS Preprocessors (SASS & LESS)
An Introduction to CSS Preprocessors (SASS & LESS)
 
Introduction to SharePoint 2013
Introduction to SharePoint 2013Introduction to SharePoint 2013
Introduction to SharePoint 2013
 
An Overview of Blackberry 10
An Overview of Blackberry 10An Overview of Blackberry 10
An Overview of Blackberry 10
 
StackOverflow Architectural Overview
StackOverflow Architectural OverviewStackOverflow Architectural Overview
StackOverflow Architectural Overview
 
Enterprise Mobility - An Introduction
Enterprise Mobility - An IntroductionEnterprise Mobility - An Introduction
Enterprise Mobility - An Introduction
 
Distributed and Fault Tolerant Realtime Computation with Apache Storm, Apache...
Distributed and Fault Tolerant Realtime Computation with Apache Storm, Apache...Distributed and Fault Tolerant Realtime Computation with Apache Storm, Apache...
Distributed and Fault Tolerant Realtime Computation with Apache Storm, Apache...
 
Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to Docker
 
Introduction to Enterprise Service Bus
Introduction to Enterprise Service BusIntroduction to Enterprise Service Bus
Introduction to Enterprise Service Bus
 
NOSQL Database: Apache Cassandra
NOSQL Database: Apache CassandraNOSQL Database: Apache Cassandra
NOSQL Database: Apache Cassandra
 
Regular Expression in Action
Regular Expression in ActionRegular Expression in Action
Regular Expression in Action
 
HTTP Server Push Techniques
HTTP Server Push TechniquesHTTP Server Push Techniques
HTTP Server Push Techniques
 
Best Practices of Software Development
Best Practices of Software DevelopmentBest Practices of Software Development
Best Practices of Software Development
 
Offline Data Access in Enterprise Mobility
Offline Data Access in Enterprise MobilityOffline Data Access in Enterprise Mobility
Offline Data Access in Enterprise Mobility
 
Realtime and Synchronous Applications
Realtime and Synchronous ApplicationsRealtime and Synchronous Applications
Realtime and Synchronous Applications
 
Web Performance & Scalability Tools
Web Performance & Scalability ToolsWeb Performance & Scalability Tools
Web Performance & Scalability Tools
 
Andriod - Technical Review
Andriod - Technical ReviewAndriod - Technical Review
Andriod - Technical Review
 
Web Application Security - Folio3
Web Application Security - Folio3Web Application Security - Folio3
Web Application Security - Folio3
 
Front End Oprtimization
Front End OprtimizationFront End Oprtimization
Front End Oprtimization
 
Dimensional Modelling - Basic Concept
Dimensional Modelling - Basic ConceptDimensional Modelling - Basic Concept
Dimensional Modelling - Basic Concept
 
NetSuite Integration Solutions - Folio3
NetSuite Integration Solutions - Folio3NetSuite Integration Solutions - Folio3
NetSuite Integration Solutions - Folio3
 

Recently uploaded

Passbook project document_april_21__.pdf
Passbook project document_april_21__.pdfPassbook project document_april_21__.pdf
Passbook project document_april_21__.pdfvaibhavkanaujia
 
Architecture case study India Habitat Centre, Delhi.pdf
Architecture case study India Habitat Centre, Delhi.pdfArchitecture case study India Habitat Centre, Delhi.pdf
Architecture case study India Habitat Centre, Delhi.pdfSumit Lathwal
 
How to Be Famous in your Field just visit our Site
How to Be Famous in your Field just visit our SiteHow to Be Famous in your Field just visit our Site
How to Be Famous in your Field just visit our Sitegalleryaagency
 
昆士兰大学毕业证(UQ毕业证)#文凭成绩单#真实留信学历认证永久存档
昆士兰大学毕业证(UQ毕业证)#文凭成绩单#真实留信学历认证永久存档昆士兰大学毕业证(UQ毕业证)#文凭成绩单#真实留信学历认证永久存档
昆士兰大学毕业证(UQ毕业证)#文凭成绩单#真实留信学历认证永久存档208367051
 
Top 10 Modern Web Design Trends for 2025
Top 10 Modern Web Design Trends for 2025Top 10 Modern Web Design Trends for 2025
Top 10 Modern Web Design Trends for 2025Rndexperts
 
Top 10 Modern Web Design Trends for 2025
Top 10 Modern Web Design Trends for 2025Top 10 Modern Web Design Trends for 2025
Top 10 Modern Web Design Trends for 2025Rndexperts
 
办理(宾州州立毕业证书)美国宾夕法尼亚州立大学毕业证成绩单原版一比一
办理(宾州州立毕业证书)美国宾夕法尼亚州立大学毕业证成绩单原版一比一办理(宾州州立毕业证书)美国宾夕法尼亚州立大学毕业证成绩单原版一比一
办理(宾州州立毕业证书)美国宾夕法尼亚州立大学毕业证成绩单原版一比一F La
 
在线办理ohio毕业证俄亥俄大学毕业证成绩单留信学历认证
在线办理ohio毕业证俄亥俄大学毕业证成绩单留信学历认证在线办理ohio毕业证俄亥俄大学毕业证成绩单留信学历认证
在线办理ohio毕业证俄亥俄大学毕业证成绩单留信学历认证nhjeo1gg
 
办理卡尔顿大学毕业证成绩单|购买加拿大文凭证书
办理卡尔顿大学毕业证成绩单|购买加拿大文凭证书办理卡尔顿大学毕业证成绩单|购买加拿大文凭证书
办理卡尔顿大学毕业证成绩单|购买加拿大文凭证书zdzoqco
 
NO1 Famous Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Add...
NO1 Famous Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Add...NO1 Famous Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Add...
NO1 Famous Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Add...Amil baba
 
FiveHypotheses_UIDMasterclass_18April2024.pdf
FiveHypotheses_UIDMasterclass_18April2024.pdfFiveHypotheses_UIDMasterclass_18April2024.pdf
FiveHypotheses_UIDMasterclass_18April2024.pdfShivakumar Viswanathan
 
定制(RMIT毕业证书)澳洲墨尔本皇家理工大学毕业证成绩单原版一比一
定制(RMIT毕业证书)澳洲墨尔本皇家理工大学毕业证成绩单原版一比一定制(RMIT毕业证书)澳洲墨尔本皇家理工大学毕业证成绩单原版一比一
定制(RMIT毕业证书)澳洲墨尔本皇家理工大学毕业证成绩单原版一比一lvtagr7
 
Design principles on typography in design
Design principles on typography in designDesign principles on typography in design
Design principles on typography in designnooreen17
 
PORTFOLIO DE ARQUITECTURA CRISTOBAL HERAUD 2024
PORTFOLIO DE ARQUITECTURA CRISTOBAL HERAUD 2024PORTFOLIO DE ARQUITECTURA CRISTOBAL HERAUD 2024
PORTFOLIO DE ARQUITECTURA CRISTOBAL HERAUD 2024CristobalHeraud
 
'CASE STUDY OF INDIRA PARYAVARAN BHAVAN DELHI ,
'CASE STUDY OF INDIRA PARYAVARAN BHAVAN DELHI ,'CASE STUDY OF INDIRA PARYAVARAN BHAVAN DELHI ,
'CASE STUDY OF INDIRA PARYAVARAN BHAVAN DELHI ,Aginakm1
 
Mookuthi is an artisanal nose ornament brand based in Madras.
Mookuthi is an artisanal nose ornament brand based in Madras.Mookuthi is an artisanal nose ornament brand based in Madras.
Mookuthi is an artisanal nose ornament brand based in Madras.Mookuthi
 
毕业文凭制作#回国入职#diploma#degree澳洲弗林德斯大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree澳洲弗林德斯大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree 毕业文凭制作#回国入职#diploma#degree澳洲弗林德斯大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree澳洲弗林德斯大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree ttt fff
 
专业一比一美国亚利桑那大学毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degree
专业一比一美国亚利桑那大学毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degree专业一比一美国亚利桑那大学毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degree
专业一比一美国亚利桑那大学毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degreeyuu sss
 
办理(USYD毕业证书)澳洲悉尼大学毕业证成绩单原版一比一
办理(USYD毕业证书)澳洲悉尼大学毕业证成绩单原版一比一办理(USYD毕业证书)澳洲悉尼大学毕业证成绩单原版一比一
办理(USYD毕业证书)澳洲悉尼大学毕业证成绩单原版一比一diploma 1
 

Recently uploaded (20)

Passbook project document_april_21__.pdf
Passbook project document_april_21__.pdfPassbook project document_april_21__.pdf
Passbook project document_april_21__.pdf
 
Architecture case study India Habitat Centre, Delhi.pdf
Architecture case study India Habitat Centre, Delhi.pdfArchitecture case study India Habitat Centre, Delhi.pdf
Architecture case study India Habitat Centre, Delhi.pdf
 
Call Girls in Pratap Nagar, 9953056974 Escort Service
Call Girls in Pratap Nagar,  9953056974 Escort ServiceCall Girls in Pratap Nagar,  9953056974 Escort Service
Call Girls in Pratap Nagar, 9953056974 Escort Service
 
How to Be Famous in your Field just visit our Site
How to Be Famous in your Field just visit our SiteHow to Be Famous in your Field just visit our Site
How to Be Famous in your Field just visit our Site
 
昆士兰大学毕业证(UQ毕业证)#文凭成绩单#真实留信学历认证永久存档
昆士兰大学毕业证(UQ毕业证)#文凭成绩单#真实留信学历认证永久存档昆士兰大学毕业证(UQ毕业证)#文凭成绩单#真实留信学历认证永久存档
昆士兰大学毕业证(UQ毕业证)#文凭成绩单#真实留信学历认证永久存档
 
Top 10 Modern Web Design Trends for 2025
Top 10 Modern Web Design Trends for 2025Top 10 Modern Web Design Trends for 2025
Top 10 Modern Web Design Trends for 2025
 
Top 10 Modern Web Design Trends for 2025
Top 10 Modern Web Design Trends for 2025Top 10 Modern Web Design Trends for 2025
Top 10 Modern Web Design Trends for 2025
 
办理(宾州州立毕业证书)美国宾夕法尼亚州立大学毕业证成绩单原版一比一
办理(宾州州立毕业证书)美国宾夕法尼亚州立大学毕业证成绩单原版一比一办理(宾州州立毕业证书)美国宾夕法尼亚州立大学毕业证成绩单原版一比一
办理(宾州州立毕业证书)美国宾夕法尼亚州立大学毕业证成绩单原版一比一
 
在线办理ohio毕业证俄亥俄大学毕业证成绩单留信学历认证
在线办理ohio毕业证俄亥俄大学毕业证成绩单留信学历认证在线办理ohio毕业证俄亥俄大学毕业证成绩单留信学历认证
在线办理ohio毕业证俄亥俄大学毕业证成绩单留信学历认证
 
办理卡尔顿大学毕业证成绩单|购买加拿大文凭证书
办理卡尔顿大学毕业证成绩单|购买加拿大文凭证书办理卡尔顿大学毕业证成绩单|购买加拿大文凭证书
办理卡尔顿大学毕业证成绩单|购买加拿大文凭证书
 
NO1 Famous Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Add...
NO1 Famous Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Add...NO1 Famous Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Add...
NO1 Famous Amil Baba In Karachi Kala Jadu In Karachi Amil baba In Karachi Add...
 
FiveHypotheses_UIDMasterclass_18April2024.pdf
FiveHypotheses_UIDMasterclass_18April2024.pdfFiveHypotheses_UIDMasterclass_18April2024.pdf
FiveHypotheses_UIDMasterclass_18April2024.pdf
 
定制(RMIT毕业证书)澳洲墨尔本皇家理工大学毕业证成绩单原版一比一
定制(RMIT毕业证书)澳洲墨尔本皇家理工大学毕业证成绩单原版一比一定制(RMIT毕业证书)澳洲墨尔本皇家理工大学毕业证成绩单原版一比一
定制(RMIT毕业证书)澳洲墨尔本皇家理工大学毕业证成绩单原版一比一
 
Design principles on typography in design
Design principles on typography in designDesign principles on typography in design
Design principles on typography in design
 
PORTFOLIO DE ARQUITECTURA CRISTOBAL HERAUD 2024
PORTFOLIO DE ARQUITECTURA CRISTOBAL HERAUD 2024PORTFOLIO DE ARQUITECTURA CRISTOBAL HERAUD 2024
PORTFOLIO DE ARQUITECTURA CRISTOBAL HERAUD 2024
 
'CASE STUDY OF INDIRA PARYAVARAN BHAVAN DELHI ,
'CASE STUDY OF INDIRA PARYAVARAN BHAVAN DELHI ,'CASE STUDY OF INDIRA PARYAVARAN BHAVAN DELHI ,
'CASE STUDY OF INDIRA PARYAVARAN BHAVAN DELHI ,
 
Mookuthi is an artisanal nose ornament brand based in Madras.
Mookuthi is an artisanal nose ornament brand based in Madras.Mookuthi is an artisanal nose ornament brand based in Madras.
Mookuthi is an artisanal nose ornament brand based in Madras.
 
毕业文凭制作#回国入职#diploma#degree澳洲弗林德斯大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree澳洲弗林德斯大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree 毕业文凭制作#回国入职#diploma#degree澳洲弗林德斯大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree澳洲弗林德斯大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
 
专业一比一美国亚利桑那大学毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degree
专业一比一美国亚利桑那大学毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degree专业一比一美国亚利桑那大学毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degree
专业一比一美国亚利桑那大学毕业证成绩单pdf电子版制作修改#真实工艺展示#真实防伪#diploma#degree
 
办理(USYD毕业证书)澳洲悉尼大学毕业证成绩单原版一比一
办理(USYD毕业证书)澳洲悉尼大学毕业证成绩单原版一比一办理(USYD毕业证书)澳洲悉尼大学毕业证成绩单原版一比一
办理(USYD毕业证书)澳洲悉尼大学毕业证成绩单原版一比一
 

Domain Driven Design

  • 1. Domain Driven Design Using Laravel by Waqar Alamgir @folio_3 www.folio3.com Copyright 2015
  • 4. Lets Look at some Concepts 1. MVC Design Pattern 2. Entities 3. Active Records @folio_3 www.folio3.com Copyright 2015
  • 6. Entities “Many objects are found fundamentally by their attributes but rather by a thread of continuity and identity” – Eric Evans @folio_3 www.folio3.com Copyright 2015
  • 7. Person Waqar Alamgir Age 26 From Karachi Waqar Alamgir Age 26 From Karachi @folio_3 www.folio3.com Copyright 2015
  • 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 @folio_3 www.folio3.com Copyright 2015
  • 10. 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. Laravel Framewrok @folio_3 Copyright 2015www.folio3.com
  • 11. That’s not DDD @folio_3 www.folio3.com Copyright 2015
  • 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. @folio_3 www.folio3.com Copyright 2015
  • 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 @folio_3 www.folio3.com Copyright 2015
  • 14. What is Command Meat of the application Controller Artisan Command Queue Worker Whatever @folio_3 www.folio3.com Copyright 2015
  • 15. What is Command Meat of the application Commands i.e. Register Member Command @folio_3 www.folio3.com Copyright 2015
  • 16. What is Command Meat of the application Commands i.e. Register Member Command @folio_3 www.folio3.com Copyright 2015
  • 17. Advantages 1. No business policy in your controller 2. Your code shows intent 3. A single dedicated flow per use case 4. A single point of entry per use case 5. Easy to see which use cases are implemented @folio_3 www.folio3.com Copyright 2015
  • 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; } } @folio_3 www.folio3.com Copyright 2015
  • 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; } } @folio_3 www.folio3.com Copyright 2015
  • 20. The Final Destination Register Member Handler Register Member Command Meat of the application @folio_3 www.folio3.com Copyright 2015
  • 21. The Final Destination Register Member Handler Register Member Command Meat of the application Command Bus @folio_3 www.folio3.com Copyright 2015
  • 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); }} @folio_3 www.folio3.com Copyright 2015
  • 24. How Does The Mapper Know? @folio_3 www.folio3.com Copyright 2015
  • 25. One Handle Per Command @folio_3 www.folio3.com Copyright 2015
  • 26. Let’s Look at very basic Register Member Command *without any sequence* @folio_3 www.folio3.com Copyright 2015
  • 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); } } @folio_3 www.folio3.com Copyright 2015
  • 28. class Member extends Eloquent { public static function register($displayName , $email , $password) { $member = new static([ ‘display_name’ => $displayName, ‘email’ => $email, ‘password’ => $password ]); return $member; } } @folio_3 www.folio3.com Copyright 2015
  • 30. Flow Review PRESENTATION LAYER Command SERVICE LAYER COMMAND BUS Command Handler DOMAIN Entities Repositories @folio_3 www.folio3.com Copyright 2015
  • 32. Simple Sequence Member Registers Subscribe to Mail Chimp Send Welcome Email Queue up 7 Day Email @folio_3 www.folio3.com Copyright 2015
  • 33. Domain Events Trigger Listeners Raise Event Typical PUB-SUB pattern Dispatch Event @folio_3 www.folio3.com Copyright 2015
  • 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 @folio_3 www.folio3.com Copyright 2015
  • 35. Events/ Listener Breakdown Member Registers Subscribe to Mail Chimp Send Welcome Email Queue up 7 Day Email @folio_3 www.folio3.com Copyright 2015
  • 36. class MemberRegistered { public $member; public function __construct(Member $member) { $this->member = $member; } } class SendWelcomeEmail implements Listener { public function handle($event) { Mailer ::Queue(…); } } @folio_3 www.folio3.com Copyright 2015
  • 38. class EventGenerator { protected $pendingEvents = []; public function raise($event) { $this->pendingEvents = $event; } public function releaseEvents() { $events = $this->pendingEvents; $this->pendingEvents = [] ; return $events; } } @folio_3 www.folio3.com Copyright 2015
  • 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; } } @folio_3 www.folio3.com Copyright 2015
  • 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) ; @folio_3 www.folio3.com Copyright 2015
  • 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()) ; } } @folio_3 www.folio3.com Copyright 2015
  • 42. More Information About DDD Domain-Driven Design: Tackling Complexity in the Heart of Software - Eric Evans Implementing Domain-Driven Design- Vaughn Vernon @folio_3 www.folio3.com Copyright 2015