SlideShare ist ein Scribd-Unternehmen logo
1 von 60
Downloaden Sie, um offline zu lesen
TrueNorthPHP 2014 
Beyond MVC: From 
Model to Domain Jeremy Cook
What is a domain?
“a specified sphere of activity or knowledge.” 
–http://www.oxforddictionaries.com/definition/english/domain
“A domain is a field of study that defines a set of 
common requirements, terminology, and 
functionality for any software program 
constructed to solve a problem…” 
–http://en.wikipedia.org/wiki/Domain_(software_engineering)
What is MVC?
Interaction of MVC Layers 
Model! 
User 
Manipulates 
Controller! 
Uses 
Updates 
View! 
Sees
Interaction of MVC Layers 
User 
Model! 
Controller! 
View!
Problems with ‘web’ MVC 
❖ Easy to muddy responsibilities in the controller! 
❖ Use of the term ‘Model’ is an issue…! 
❖ Offers no guidance in modelling the most critical part of 
our apps: the model or domain
“Model–view–controller (MVC) is a software 
architectural pattern for implementing user 
interfaces.” 
–http://en.wikipedia.org/wiki/Model–view–controller
This talk is about managing 
complexity
Introducing Action Domain 
Responder
What is Action Domain Responder? 
❖ Created by Paul M Jones! 
❖ Web specific refinement of MVC! 
❖ Designed to map more closely to what actually happens 
in the lifecycle of a web request
What is Action Domain Responder? 
❖ Model! 
❖ View! 
❖ Controller
What is Action Domain Responder? 
❖ Controller! 
❖ Model! 
❖ View
What is Action Domain Responder? 
❖ Controller Action! 
❖ Model Domain! 
❖ View Responder
Action 
❖ In ADR an action is mapped to a single class or closure! 
❖ Creates a single place for all code dealing with an action! 
❖ Does not directly create a view or HTTP response
Responder 
❖ ADR recognises that a web response is more than a 
view! 
❖ Action instantiates a responder object and injects 
domain data in it! 
❖ Responder is responsible for generating all aspects of 
the response
Domain 
❖ ADR offers no help on modelling a domain…! 
❖ …but at least Paul calls it a domain!! 
❖ Other patterns later will offer more help here
ADR Example 
<?php! 
! 
interface ActionInterface {! 
public function __construct(ResponderFactoryInterface $factory);! 
public function __invoke(RequestInterface $request);! 
}!
ADR Example 
<?php! 
! 
class FooAction implements ActionInterface {! 
protected $responderFactory;! 
! 
public function __construct(ResponderFactoryInterface $factory) {! 
$this->responderFactory = $factory;! 
}! 
! 
public function __invoke(RequestInterface $request) {! 
//Domain logic here! 
$responder = $this->responderFactory->generateForRequest($request);! 
! 
return $responder();! 
}! 
}!
Further information on ADR 
❖ https://github.com/pmjones/adr
Hexagonal Architecture
Ports and Adapters 
Hexagonal Architecture
What’s wrong with ‘Hexagonal Architecture’? 
❖ Has nothing to do with hexagons! 
❖ Has nothing to do with the number 6! 
❖ Ports and adapters describes what this actually does
What are Ports and Adapters? 
❖ Invented by Alistair Cockburn! 
❖ Architectural pattern for isolating an application from 
it’s inputs.
“Allow an application to equally be driven by 
users, programs, automated test or batch scripts, 
and to be developed and tested in isolation from 
its eventual run-time devices and databases.” 
–Alistair Cockburn
“Allow an application to equally be driven by 
users, programs, automated test or batch scripts, 
and to be developed and tested in isolation from 
its eventual run-time devices and databases.” 
–Alistair Cockburn
Ports and Adapters 
Application
Ports and Adapters 
Application
Ports and Adapters 
Adapters 
Adapters 
Application 
Adapters 
Adapters 
Adapters 
Adapters
Ports and Adapters 
Domain 
Adapters 
Adapters 
Adapters 
Adapters 
Adapters 
Adapters
HTTP Adapter 
<?php! 
! 
class FooAction implements ActionInterface {! 
protected $responderFactory;! 
protected $service;! 
! 
public function __construct(ResponderFactoryInterface $factory, 
ApplicationServiceInterface $service) {! 
$this->responderFactory = $factory;! 
$this->service = $service;! 
}! 
! 
public function __invoke(RequestInterface $request) {! 
$result = $this->service->__invoke($request->getParamsArray());! 
$responder = $this->responderFactory->generateForRequest($request);! 
! 
return $responder($result);! 
}! 
}!
AMQP Adapter 
<?php! 
! 
class FooConsumer implements AMQPConsumer {! 
protected $service;! 
! 
public function __construct(ApplicationServiceInterface $service) {! 
$this->service = $service;! 
}! 
! 
public function __invoke(AMQPMessage $msg) {! 
$data = json_decode($msg->body, true);! 
$result = $this->service->__invoke($data);! 
if ($result->isStatusOk()) {! 
$msg->delivery_info['channel']! 
->basic_ack($msg->delivery_info['delivery_tag']);! 
}! 
}! 
}!
Advantages of Ports and Adapters 
❖ Encapsulation of the domain! 
❖ Allows development of the domain and adapters to 
be independent! 
❖ Allows better end to end testability of the domain! 
❖ Makes it simple to add new entry points to an app
Further information on Ports and Adapters 
❖ The original article introducing ports and adapters: 
http://alistair.cockburn.us/Hexagonal+architecture
Introducing Domain Driven 
Design
What is Domain Driven Design? 
❖ Concept coined by Eric Evans! 
❖ Ideas can be grouped into two related areas:! 
❖ Architectural patterns! 
❖ Object patterns
DDD Interaction Map
Read some books
Architectural patterns
Your app has multiple domains
Ubiquitous language 
❖ Develop a shared language to describe each domain 
and model the software after it! 
❖ The domain should be an expression of the ubiquitous 
language in code! 
❖ Aim is to unite all members of a product team, from 
developers to product managers
Bounded contexts 
❖ Represents the boundary around a domain! 
❖ All code within a domain is completely encapsulated 
with specific entry points! 
❖ Code and concepts are unique per domain
Context map 
❖ Describes relationships between domains! 
❖ Outlines all points of contact between domains! 
❖ Can also include existing systems
Object patterns
Entities 
❖ Represents a concept in your domain! 
❖ Each instance of a entity should be considered unique! 
❖ Houses logic and operation on the concept
Value Objects 
❖ Used when you only care about the attributes and logic 
of the concept! 
❖ Immutable! 
❖ All methods must be side effect free! 
❖ Mutator methods must return a new instance of the 
value object! 
❖ Prefer value objects over simple types
Value Objects 
<?php! 
! 
class Person {! 
public function __construct($firstName, $lastName) {! 
//Code here! 
}! 
}! 
! 
$person = new Person('Cook', 'Jeremy'); //WHOOPS!!
Value Objects 
<?php! 
! 
class Firstname {! 
protected $firstname;! 
! 
public function __construct($firstname) {! 
if (! is_string($firstname)) {! 
throw new InvalidArgumentException(/**ErrorMessage**/);! 
}! 
$this->firstname = $firstname;! 
}! 
! 
public function __toString() {! 
return $this->firstname;! 
}! 
}!
Value Objects 
<?php! 
! 
class Person {! 
public function __construct(Firstname $firstName, Lastname $lastName) {! 
//Code here! 
}! 
}! 
! 
//This will now cause an error! 
$person = new Person(new Lastname('Cook'), new Firstname('Jeremy'));!
Entities vs Value Objects 
!== 
Bank Account 
Owner: Jeremy 
Balance: $1,000,000 
Account #: 12345 
=== 
Currency 
Name: Canadian Dollar 
Abbr: CAD 
Symbol: $ 
Bank Account 
Owner: Jeremy 
Balance: $1,000,000 
Account #: 12346 
Currency 
Name: Canadian Dollar 
Abbr: CAD 
Symbol: $
Aggregates 
❖ A collection of entities contained by another entity! 
❖ The containing entity is the aggregate root! 
❖ Individual aggregate instances can only be accessed 
through the aggregate root
Repositories 
❖ A specialised adapter that maps entities to and from the 
persistence layer! 
❖ Provides methods to retrieve entities and save them! 
❖ Abstracts the details of the persistence layer away from 
the domain
Domain Services 
❖ Encapsulates an operation that is not owned by another 
part of the domain model! 
❖ A good service has three properties:! 
❖ Models a domain concept that does not conceptually 
belong to an entity or value object! 
❖ Stateless! 
❖ Defined in terms of the domain model
Domain Services 
<?php! 
! 
class MoneyTransfer {! 
public static function transferBetweenAccounts(Account $from, Account 
$to, Money $amount) {! 
$from->debitForTransfer($money, $to);! 
$to->creditFromTransfer($money, $from);! 
}! 
}! 
! 
//In the application service...! 
$from = $accountRepository->findByAccNumber('123456');! 
$to = $accountRepository->findByAccNumber('123457');! 
$money = new Money('100', new Currency('CAD'));! 
MoneyTransfer::transferBetweenAccounts($from, $to, $money);!
Domain Events 
❖ Allows a domain to signal that something as happened! 
❖ Full part of the domain and a representation of 
something that has happened! 
❖ Used to signal something that might trigger a state 
change in another domain
Domain Events 
<?php! 
! 
class MoneyTransfer {! 
public static function transferBetweenAccounts(Account $from, Account 
$to, Money $amount) {! 
$from->debitForTransfer($money, $to);! 
$to->creditFromTransfer($money, $from);! 
}! 
}! 
! 
//In the application service...! 
$from = $accountRepository->findByAccNumber('123456');! 
$to = $accountRepository->findByAccNumber('123457');! 
$money = new Money('100', new Currency('CAD'));! 
MoneyTransfer::transferBetweenAccounts($from, $to, $money);! 
$event = EventFactory::createEventForSuccessfulAccountTransfer($from, $to, 
$money);! 
$eventType = EventTypes::SUCCESSFUL_MONEY_TRANSFER;! 
$eventDispatcher->raiseEvent($eventType, $event);
Further Information on DDD 
❖ Eric Evans! 
❖ “Domain Driven Design” book! 
❖ Short introduction: https://domainlanguage.com/ddd/ 
patterns/DDD_Reference_2011-01-31.pdf! 
❖ Implementing Domain Driven Design by Vaughn Vernon! 
❖ Mathias Verraes: http://verraes.net! 
❖ DDD in PHP Google Group: https://groups.google.com/ 
forum/#!forum/dddinphp
Avoid projects like this!
Thanks for listening! 
❖ Any questions?! 
❖ Feel free to contact me! 
❖ jeremycook0@gmail.com! 
❖ @JCook21

Weitere ähnliche Inhalte

Was ist angesagt?

Hello World on Slim Framework 3.x
Hello World on Slim Framework 3.xHello World on Slim Framework 3.x
Hello World on Slim Framework 3.xRyan Szrama
 
The Naked Bundle - Symfony Live London 2014
The Naked Bundle - Symfony Live London 2014The Naked Bundle - Symfony Live London 2014
The Naked Bundle - Symfony Live London 2014Matthias Noback
 
How Symfony Changed My Life
How Symfony Changed My LifeHow Symfony Changed My Life
How Symfony Changed My LifeMatthias Noback
 
Isomorphic App Development with Ruby and Volt - Rubyconf2014
Isomorphic App Development with Ruby and Volt - Rubyconf2014Isomorphic App Development with Ruby and Volt - Rubyconf2014
Isomorphic App Development with Ruby and Volt - Rubyconf2014ryanstout
 
Crafting Quality PHP Applications (PHP Joburg Oct 2019)
Crafting Quality PHP Applications (PHP Joburg Oct 2019)Crafting Quality PHP Applications (PHP Joburg Oct 2019)
Crafting Quality PHP Applications (PHP Joburg Oct 2019)James Titcumb
 
Best practices for crafting high quality PHP apps (Bulgaria 2019)
Best practices for crafting high quality PHP apps (Bulgaria 2019)Best practices for crafting high quality PHP apps (Bulgaria 2019)
Best practices for crafting high quality PHP apps (Bulgaria 2019)James Titcumb
 
"Managing API Complexity". Matthew Flaming, Temboo
"Managing API Complexity". Matthew Flaming, Temboo"Managing API Complexity". Matthew Flaming, Temboo
"Managing API Complexity". Matthew Flaming, TembooYandex
 
Keeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro FrameworkKeeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro FrameworkJeremy Kendall
 
Best practices for crafting high quality PHP apps (PHP South Africa 2018)
Best practices for crafting high quality PHP apps (PHP South Africa 2018)Best practices for crafting high quality PHP apps (PHP South Africa 2018)
Best practices for crafting high quality PHP apps (PHP South Africa 2018)James Titcumb
 
Best practices for crafting high quality PHP apps - PHP UK 2019
Best practices for crafting high quality PHP apps - PHP UK 2019Best practices for crafting high quality PHP apps - PHP UK 2019
Best practices for crafting high quality PHP apps - PHP UK 2019James Titcumb
 
Best practices for crafting high quality PHP apps (ScotlandPHP 2018)
Best practices for crafting high quality PHP apps (ScotlandPHP 2018)Best practices for crafting high quality PHP apps (ScotlandPHP 2018)
Best practices for crafting high quality PHP apps (ScotlandPHP 2018)James Titcumb
 
Rails for Beginners - Le Wagon
Rails for Beginners - Le WagonRails for Beginners - Le Wagon
Rails for Beginners - Le WagonAlex Benoit
 
Roman Schejbal: From Madness To Reason
Roman Schejbal: From Madness To ReasonRoman Schejbal: From Madness To Reason
Roman Schejbal: From Madness To ReasonDevelcz
 
Dip Your Toes in the Sea of Security (ConFoo YVR 2017)
Dip Your Toes in the Sea of Security (ConFoo YVR 2017)Dip Your Toes in the Sea of Security (ConFoo YVR 2017)
Dip Your Toes in the Sea of Security (ConFoo YVR 2017)James Titcumb
 
Slim RedBeanPHP and Knockout
Slim RedBeanPHP and KnockoutSlim RedBeanPHP and Knockout
Slim RedBeanPHP and KnockoutVic Metcalfe
 
Deliver Business Value Faster with AWS Step Functions
Deliver Business Value Faster with AWS Step FunctionsDeliver Business Value Faster with AWS Step Functions
Deliver Business Value Faster with AWS Step FunctionsDaniel Zivkovic
 
Don't worry be API with Slim framework and Joomla
Don't worry be API with Slim framework and JoomlaDon't worry be API with Slim framework and Joomla
Don't worry be API with Slim framework and JoomlaPierre-André Vullioud
 
Keeping it small: Getting to know the Slim micro framework
Keeping it small: Getting to know the Slim micro frameworkKeeping it small: Getting to know the Slim micro framework
Keeping it small: Getting to know the Slim micro frameworkJeremy Kendall
 

Was ist angesagt? (20)

Hello World on Slim Framework 3.x
Hello World on Slim Framework 3.xHello World on Slim Framework 3.x
Hello World on Slim Framework 3.x
 
The Naked Bundle - Symfony Live London 2014
The Naked Bundle - Symfony Live London 2014The Naked Bundle - Symfony Live London 2014
The Naked Bundle - Symfony Live London 2014
 
How Symfony Changed My Life
How Symfony Changed My LifeHow Symfony Changed My Life
How Symfony Changed My Life
 
Isomorphic App Development with Ruby and Volt - Rubyconf2014
Isomorphic App Development with Ruby and Volt - Rubyconf2014Isomorphic App Development with Ruby and Volt - Rubyconf2014
Isomorphic App Development with Ruby and Volt - Rubyconf2014
 
Crafting Quality PHP Applications (PHP Joburg Oct 2019)
Crafting Quality PHP Applications (PHP Joburg Oct 2019)Crafting Quality PHP Applications (PHP Joburg Oct 2019)
Crafting Quality PHP Applications (PHP Joburg Oct 2019)
 
Step objects
Step objectsStep objects
Step objects
 
Best practices for crafting high quality PHP apps (Bulgaria 2019)
Best practices for crafting high quality PHP apps (Bulgaria 2019)Best practices for crafting high quality PHP apps (Bulgaria 2019)
Best practices for crafting high quality PHP apps (Bulgaria 2019)
 
Volt 2015
Volt 2015Volt 2015
Volt 2015
 
"Managing API Complexity". Matthew Flaming, Temboo
"Managing API Complexity". Matthew Flaming, Temboo"Managing API Complexity". Matthew Flaming, Temboo
"Managing API Complexity". Matthew Flaming, Temboo
 
Keeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro FrameworkKeeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro Framework
 
Best practices for crafting high quality PHP apps (PHP South Africa 2018)
Best practices for crafting high quality PHP apps (PHP South Africa 2018)Best practices for crafting high quality PHP apps (PHP South Africa 2018)
Best practices for crafting high quality PHP apps (PHP South Africa 2018)
 
Best practices for crafting high quality PHP apps - PHP UK 2019
Best practices for crafting high quality PHP apps - PHP UK 2019Best practices for crafting high quality PHP apps - PHP UK 2019
Best practices for crafting high quality PHP apps - PHP UK 2019
 
Best practices for crafting high quality PHP apps (ScotlandPHP 2018)
Best practices for crafting high quality PHP apps (ScotlandPHP 2018)Best practices for crafting high quality PHP apps (ScotlandPHP 2018)
Best practices for crafting high quality PHP apps (ScotlandPHP 2018)
 
Rails for Beginners - Le Wagon
Rails for Beginners - Le WagonRails for Beginners - Le Wagon
Rails for Beginners - Le Wagon
 
Roman Schejbal: From Madness To Reason
Roman Schejbal: From Madness To ReasonRoman Schejbal: From Madness To Reason
Roman Schejbal: From Madness To Reason
 
Dip Your Toes in the Sea of Security (ConFoo YVR 2017)
Dip Your Toes in the Sea of Security (ConFoo YVR 2017)Dip Your Toes in the Sea of Security (ConFoo YVR 2017)
Dip Your Toes in the Sea of Security (ConFoo YVR 2017)
 
Slim RedBeanPHP and Knockout
Slim RedBeanPHP and KnockoutSlim RedBeanPHP and Knockout
Slim RedBeanPHP and Knockout
 
Deliver Business Value Faster with AWS Step Functions
Deliver Business Value Faster with AWS Step FunctionsDeliver Business Value Faster with AWS Step Functions
Deliver Business Value Faster with AWS Step Functions
 
Don't worry be API with Slim framework and Joomla
Don't worry be API with Slim framework and JoomlaDon't worry be API with Slim framework and Joomla
Don't worry be API with Slim framework and Joomla
 
Keeping it small: Getting to know the Slim micro framework
Keeping it small: Getting to know the Slim micro frameworkKeeping it small: Getting to know the Slim micro framework
Keeping it small: Getting to know the Slim micro framework
 

Andere mochten auch

Mobile marketing cómo implementarlo
Mobile marketing cómo implementarloMobile marketing cómo implementarlo
Mobile marketing cómo implementarloInterlat
 
Memories of WMS G.A.T.E. 8th grade 2010
Memories of WMS G.A.T.E. 8th grade 2010Memories of WMS G.A.T.E. 8th grade 2010
Memories of WMS G.A.T.E. 8th grade 2010Andrea L. Wurm
 
Victor hu1
Victor hu1Victor hu1
Victor hu1Marisagg
 
imetodo_formacion.pdf
imetodo_formacion.pdfimetodo_formacion.pdf
imetodo_formacion.pdfimétodo
 
C O N T A C T O
C O N T A C T OC O N T A C T O
C O N T A C T Oquisqueya1
 
Vietnam Boletín Informativo Octubre 2010
Vietnam Boletín Informativo Octubre 2010Vietnam Boletín Informativo Octubre 2010
Vietnam Boletín Informativo Octubre 2010Juan Inoriza
 
Tarea en clase diapositivas
Tarea en clase  diapositivasTarea en clase  diapositivas
Tarea en clase diapositivasDiana Imbaquingo
 
Consideraciones consideraciones didacticas para enseñar y jugar
Consideraciones consideraciones didacticas para enseñar y jugarConsideraciones consideraciones didacticas para enseñar y jugar
Consideraciones consideraciones didacticas para enseñar y jugartogueda
 
Proven Strategies to Leverage Your Customer Community to Grow Your Business
Proven Strategies to Leverage Your Customer Community to Grow Your BusinessProven Strategies to Leverage Your Customer Community to Grow Your Business
Proven Strategies to Leverage Your Customer Community to Grow Your BusinessSocious
 
Catálogo mitsubishi electric aire acondicionado msz fd - msz-ge mfz-ka
Catálogo mitsubishi electric aire acondicionado msz fd - msz-ge mfz-kaCatálogo mitsubishi electric aire acondicionado msz fd - msz-ge mfz-ka
Catálogo mitsubishi electric aire acondicionado msz fd - msz-ge mfz-kaRooibos13
 
Career Guide International Careers
Career Guide International CareersCareer Guide International Careers
Career Guide International Careershanzoh
 
Capacitación TFS - Build
Capacitación TFS - BuildCapacitación TFS - Build
Capacitación TFS - BuildAriel Bender
 

Andere mochten auch (20)

Mobile marketing cómo implementarlo
Mobile marketing cómo implementarloMobile marketing cómo implementarlo
Mobile marketing cómo implementarlo
 
Abdellah Mahdar CV
Abdellah Mahdar CVAbdellah Mahdar CV
Abdellah Mahdar CV
 
Proyecto de Inversión en España - ES
Proyecto de Inversión en España - ESProyecto de Inversión en España - ES
Proyecto de Inversión en España - ES
 
Issuu tarifas
Issuu tarifasIssuu tarifas
Issuu tarifas
 
Revista n52
Revista n52Revista n52
Revista n52
 
Memories of WMS G.A.T.E. 8th grade 2010
Memories of WMS G.A.T.E. 8th grade 2010Memories of WMS G.A.T.E. 8th grade 2010
Memories of WMS G.A.T.E. 8th grade 2010
 
Barcamp Matej Tomasovsky
Barcamp Matej TomasovskyBarcamp Matej Tomasovsky
Barcamp Matej Tomasovsky
 
Foda
FodaFoda
Foda
 
High-Profile May 2012
High-Profile May 2012High-Profile May 2012
High-Profile May 2012
 
eBRIDGE Toolkit
eBRIDGE ToolkiteBRIDGE Toolkit
eBRIDGE Toolkit
 
Victor hu1
Victor hu1Victor hu1
Victor hu1
 
imetodo_formacion.pdf
imetodo_formacion.pdfimetodo_formacion.pdf
imetodo_formacion.pdf
 
C O N T A C T O
C O N T A C T OC O N T A C T O
C O N T A C T O
 
Vietnam Boletín Informativo Octubre 2010
Vietnam Boletín Informativo Octubre 2010Vietnam Boletín Informativo Octubre 2010
Vietnam Boletín Informativo Octubre 2010
 
Tarea en clase diapositivas
Tarea en clase  diapositivasTarea en clase  diapositivas
Tarea en clase diapositivas
 
Consideraciones consideraciones didacticas para enseñar y jugar
Consideraciones consideraciones didacticas para enseñar y jugarConsideraciones consideraciones didacticas para enseñar y jugar
Consideraciones consideraciones didacticas para enseñar y jugar
 
Proven Strategies to Leverage Your Customer Community to Grow Your Business
Proven Strategies to Leverage Your Customer Community to Grow Your BusinessProven Strategies to Leverage Your Customer Community to Grow Your Business
Proven Strategies to Leverage Your Customer Community to Grow Your Business
 
Catálogo mitsubishi electric aire acondicionado msz fd - msz-ge mfz-ka
Catálogo mitsubishi electric aire acondicionado msz fd - msz-ge mfz-kaCatálogo mitsubishi electric aire acondicionado msz fd - msz-ge mfz-ka
Catálogo mitsubishi electric aire acondicionado msz fd - msz-ge mfz-ka
 
Career Guide International Careers
Career Guide International CareersCareer Guide International Careers
Career Guide International Careers
 
Capacitación TFS - Build
Capacitación TFS - BuildCapacitación TFS - Build
Capacitación TFS - Build
 

Ähnlich wie Beyond MVC: from Model to Domain

Beyond MVC: from Model to Domain
Beyond MVC: from Model to DomainBeyond MVC: from Model to Domain
Beyond MVC: from Model to DomainJeremy Cook
 
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
 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with ExamplesGabriele Lana
 
Nodejsexplained 101116115055-phpapp02
Nodejsexplained 101116115055-phpapp02Nodejsexplained 101116115055-phpapp02
Nodejsexplained 101116115055-phpapp02Sunny Gupta
 
PHP from soup to nuts Course Deck
PHP from soup to nuts Course DeckPHP from soup to nuts Course Deck
PHP from soup to nuts Course DeckrICh morrow
 
Dutch PHP Conference 2015 - The quest for global design principles
Dutch PHP Conference 2015 - The quest for global design principlesDutch PHP Conference 2015 - The quest for global design principles
Dutch PHP Conference 2015 - The quest for global design principlesMatthias Noback
 
Writing Testable Code
Writing Testable CodeWriting Testable Code
Writing Testable Codejameshalsall
 
JavaScript & Dom Manipulation
JavaScript & Dom ManipulationJavaScript & Dom Manipulation
JavaScript & Dom ManipulationMohammed Arif
 
Hexagonal architecture - message-oriented software design
Hexagonal architecture  - message-oriented software designHexagonal architecture  - message-oriented software design
Hexagonal architecture - message-oriented software designMatthias Noback
 
Relentless Refactoring
Relentless RefactoringRelentless Refactoring
Relentless RefactoringMark Rickerby
 
Streamlining Your Applications with Web Frameworks
Streamlining Your Applications with Web FrameworksStreamlining Your Applications with Web Frameworks
Streamlining Your Applications with Web Frameworksguestf7bc30
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy CodeRowan Merewood
 
Code decoupling from Symfony (and others frameworks) - PHP Conference Brasil ...
Code decoupling from Symfony (and others frameworks) - PHP Conference Brasil ...Code decoupling from Symfony (and others frameworks) - PHP Conference Brasil ...
Code decoupling from Symfony (and others frameworks) - PHP Conference Brasil ...Miguel Gallardo
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applicationselliando dias
 

Ähnlich wie Beyond MVC: from Model to Domain (20)

Beyond MVC: from Model to Domain
Beyond MVC: from Model to DomainBeyond MVC: from Model to Domain
Beyond MVC: from Model to Domain
 
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!
 
Refactoring
RefactoringRefactoring
Refactoring
 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with Examples
 
Nodejsexplained 101116115055-phpapp02
Nodejsexplained 101116115055-phpapp02Nodejsexplained 101116115055-phpapp02
Nodejsexplained 101116115055-phpapp02
 
php.pdf
php.pdfphp.pdf
php.pdf
 
PHP from soup to nuts Course Deck
PHP from soup to nuts Course DeckPHP from soup to nuts Course Deck
PHP from soup to nuts Course Deck
 
Dutch PHP Conference 2015 - The quest for global design principles
Dutch PHP Conference 2015 - The quest for global design principlesDutch PHP Conference 2015 - The quest for global design principles
Dutch PHP Conference 2015 - The quest for global design principles
 
Writing Testable Code
Writing Testable CodeWriting Testable Code
Writing Testable Code
 
JavaScript & Dom Manipulation
JavaScript & Dom ManipulationJavaScript & Dom Manipulation
JavaScript & Dom Manipulation
 
Hexagonal architecture - message-oriented software design
Hexagonal architecture  - message-oriented software designHexagonal architecture  - message-oriented software design
Hexagonal architecture - message-oriented software design
 
Relentless Refactoring
Relentless RefactoringRelentless Refactoring
Relentless Refactoring
 
Php
PhpPhp
Php
 
Hexagonal architecture in PHP
Hexagonal architecture in PHPHexagonal architecture in PHP
Hexagonal architecture in PHP
 
Hexagonal architecture
Hexagonal architectureHexagonal architecture
Hexagonal architecture
 
Streamlining Your Applications with Web Frameworks
Streamlining Your Applications with Web FrameworksStreamlining Your Applications with Web Frameworks
Streamlining Your Applications with Web Frameworks
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
Code decoupling from Symfony (and others frameworks) - PHP Conference Brasil ...
Code decoupling from Symfony (and others frameworks) - PHP Conference Brasil ...Code decoupling from Symfony (and others frameworks) - PHP Conference Brasil ...
Code decoupling from Symfony (and others frameworks) - PHP Conference Brasil ...
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applications
 
Prersentation
PrersentationPrersentation
Prersentation
 

Mehr von Jeremy Cook

Unit test your java architecture with ArchUnit
Unit test your java architecture with ArchUnitUnit test your java architecture with ArchUnit
Unit test your java architecture with ArchUnitJeremy Cook
 
Tracking your data across the fourth dimension
Tracking your data across the fourth dimensionTracking your data across the fourth dimension
Tracking your data across the fourth dimensionJeremy Cook
 
Tracking your data across the fourth dimension
Tracking your data across the fourth dimensionTracking your data across the fourth dimension
Tracking your data across the fourth dimensionJeremy Cook
 
Track your data across the fourth dimension
Track your data across the fourth dimensionTrack your data across the fourth dimension
Track your data across the fourth dimensionJeremy Cook
 
Accelerate your web app with a layer of Varnish
Accelerate your web app with a layer of VarnishAccelerate your web app with a layer of Varnish
Accelerate your web app with a layer of VarnishJeremy Cook
 
Turbo charge your logs
Turbo charge your logsTurbo charge your logs
Turbo charge your logsJeremy Cook
 
Turbo charge your logs
Turbo charge your logsTurbo charge your logs
Turbo charge your logsJeremy Cook
 
PHPUnit: from zero to hero
PHPUnit: from zero to heroPHPUnit: from zero to hero
PHPUnit: from zero to heroJeremy Cook
 

Mehr von Jeremy Cook (8)

Unit test your java architecture with ArchUnit
Unit test your java architecture with ArchUnitUnit test your java architecture with ArchUnit
Unit test your java architecture with ArchUnit
 
Tracking your data across the fourth dimension
Tracking your data across the fourth dimensionTracking your data across the fourth dimension
Tracking your data across the fourth dimension
 
Tracking your data across the fourth dimension
Tracking your data across the fourth dimensionTracking your data across the fourth dimension
Tracking your data across the fourth dimension
 
Track your data across the fourth dimension
Track your data across the fourth dimensionTrack your data across the fourth dimension
Track your data across the fourth dimension
 
Accelerate your web app with a layer of Varnish
Accelerate your web app with a layer of VarnishAccelerate your web app with a layer of Varnish
Accelerate your web app with a layer of Varnish
 
Turbo charge your logs
Turbo charge your logsTurbo charge your logs
Turbo charge your logs
 
Turbo charge your logs
Turbo charge your logsTurbo charge your logs
Turbo charge your logs
 
PHPUnit: from zero to hero
PHPUnit: from zero to heroPHPUnit: from zero to hero
PHPUnit: from zero to hero
 

Kürzlich hochgeladen

Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 

Kürzlich hochgeladen (20)

Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 

Beyond MVC: from Model to Domain

  • 1. TrueNorthPHP 2014 Beyond MVC: From Model to Domain Jeremy Cook
  • 2. What is a domain?
  • 3. “a specified sphere of activity or knowledge.” –http://www.oxforddictionaries.com/definition/english/domain
  • 4. “A domain is a field of study that defines a set of common requirements, terminology, and functionality for any software program constructed to solve a problem…” –http://en.wikipedia.org/wiki/Domain_(software_engineering)
  • 6. Interaction of MVC Layers Model! User Manipulates Controller! Uses Updates View! Sees
  • 7. Interaction of MVC Layers User Model! Controller! View!
  • 8. Problems with ‘web’ MVC ❖ Easy to muddy responsibilities in the controller! ❖ Use of the term ‘Model’ is an issue…! ❖ Offers no guidance in modelling the most critical part of our apps: the model or domain
  • 9. “Model–view–controller (MVC) is a software architectural pattern for implementing user interfaces.” –http://en.wikipedia.org/wiki/Model–view–controller
  • 10. This talk is about managing complexity
  • 12. What is Action Domain Responder? ❖ Created by Paul M Jones! ❖ Web specific refinement of MVC! ❖ Designed to map more closely to what actually happens in the lifecycle of a web request
  • 13. What is Action Domain Responder? ❖ Model! ❖ View! ❖ Controller
  • 14. What is Action Domain Responder? ❖ Controller! ❖ Model! ❖ View
  • 15. What is Action Domain Responder? ❖ Controller Action! ❖ Model Domain! ❖ View Responder
  • 16. Action ❖ In ADR an action is mapped to a single class or closure! ❖ Creates a single place for all code dealing with an action! ❖ Does not directly create a view or HTTP response
  • 17. Responder ❖ ADR recognises that a web response is more than a view! ❖ Action instantiates a responder object and injects domain data in it! ❖ Responder is responsible for generating all aspects of the response
  • 18. Domain ❖ ADR offers no help on modelling a domain…! ❖ …but at least Paul calls it a domain!! ❖ Other patterns later will offer more help here
  • 19. ADR Example <?php! ! interface ActionInterface {! public function __construct(ResponderFactoryInterface $factory);! public function __invoke(RequestInterface $request);! }!
  • 20. ADR Example <?php! ! class FooAction implements ActionInterface {! protected $responderFactory;! ! public function __construct(ResponderFactoryInterface $factory) {! $this->responderFactory = $factory;! }! ! public function __invoke(RequestInterface $request) {! //Domain logic here! $responder = $this->responderFactory->generateForRequest($request);! ! return $responder();! }! }!
  • 21. Further information on ADR ❖ https://github.com/pmjones/adr
  • 23. Ports and Adapters Hexagonal Architecture
  • 24. What’s wrong with ‘Hexagonal Architecture’? ❖ Has nothing to do with hexagons! ❖ Has nothing to do with the number 6! ❖ Ports and adapters describes what this actually does
  • 25. What are Ports and Adapters? ❖ Invented by Alistair Cockburn! ❖ Architectural pattern for isolating an application from it’s inputs.
  • 26. “Allow an application to equally be driven by users, programs, automated test or batch scripts, and to be developed and tested in isolation from its eventual run-time devices and databases.” –Alistair Cockburn
  • 27. “Allow an application to equally be driven by users, programs, automated test or batch scripts, and to be developed and tested in isolation from its eventual run-time devices and databases.” –Alistair Cockburn
  • 28. Ports and Adapters Application
  • 29. Ports and Adapters Application
  • 30. Ports and Adapters Adapters Adapters Application Adapters Adapters Adapters Adapters
  • 31. Ports and Adapters Domain Adapters Adapters Adapters Adapters Adapters Adapters
  • 32. HTTP Adapter <?php! ! class FooAction implements ActionInterface {! protected $responderFactory;! protected $service;! ! public function __construct(ResponderFactoryInterface $factory, ApplicationServiceInterface $service) {! $this->responderFactory = $factory;! $this->service = $service;! }! ! public function __invoke(RequestInterface $request) {! $result = $this->service->__invoke($request->getParamsArray());! $responder = $this->responderFactory->generateForRequest($request);! ! return $responder($result);! }! }!
  • 33. AMQP Adapter <?php! ! class FooConsumer implements AMQPConsumer {! protected $service;! ! public function __construct(ApplicationServiceInterface $service) {! $this->service = $service;! }! ! public function __invoke(AMQPMessage $msg) {! $data = json_decode($msg->body, true);! $result = $this->service->__invoke($data);! if ($result->isStatusOk()) {! $msg->delivery_info['channel']! ->basic_ack($msg->delivery_info['delivery_tag']);! }! }! }!
  • 34. Advantages of Ports and Adapters ❖ Encapsulation of the domain! ❖ Allows development of the domain and adapters to be independent! ❖ Allows better end to end testability of the domain! ❖ Makes it simple to add new entry points to an app
  • 35. Further information on Ports and Adapters ❖ The original article introducing ports and adapters: http://alistair.cockburn.us/Hexagonal+architecture
  • 37. What is Domain Driven Design? ❖ Concept coined by Eric Evans! ❖ Ideas can be grouped into two related areas:! ❖ Architectural patterns! ❖ Object patterns
  • 41. Your app has multiple domains
  • 42. Ubiquitous language ❖ Develop a shared language to describe each domain and model the software after it! ❖ The domain should be an expression of the ubiquitous language in code! ❖ Aim is to unite all members of a product team, from developers to product managers
  • 43. Bounded contexts ❖ Represents the boundary around a domain! ❖ All code within a domain is completely encapsulated with specific entry points! ❖ Code and concepts are unique per domain
  • 44. Context map ❖ Describes relationships between domains! ❖ Outlines all points of contact between domains! ❖ Can also include existing systems
  • 46. Entities ❖ Represents a concept in your domain! ❖ Each instance of a entity should be considered unique! ❖ Houses logic and operation on the concept
  • 47. Value Objects ❖ Used when you only care about the attributes and logic of the concept! ❖ Immutable! ❖ All methods must be side effect free! ❖ Mutator methods must return a new instance of the value object! ❖ Prefer value objects over simple types
  • 48. Value Objects <?php! ! class Person {! public function __construct($firstName, $lastName) {! //Code here! }! }! ! $person = new Person('Cook', 'Jeremy'); //WHOOPS!!
  • 49. Value Objects <?php! ! class Firstname {! protected $firstname;! ! public function __construct($firstname) {! if (! is_string($firstname)) {! throw new InvalidArgumentException(/**ErrorMessage**/);! }! $this->firstname = $firstname;! }! ! public function __toString() {! return $this->firstname;! }! }!
  • 50. Value Objects <?php! ! class Person {! public function __construct(Firstname $firstName, Lastname $lastName) {! //Code here! }! }! ! //This will now cause an error! $person = new Person(new Lastname('Cook'), new Firstname('Jeremy'));!
  • 51. Entities vs Value Objects !== Bank Account Owner: Jeremy Balance: $1,000,000 Account #: 12345 === Currency Name: Canadian Dollar Abbr: CAD Symbol: $ Bank Account Owner: Jeremy Balance: $1,000,000 Account #: 12346 Currency Name: Canadian Dollar Abbr: CAD Symbol: $
  • 52. Aggregates ❖ A collection of entities contained by another entity! ❖ The containing entity is the aggregate root! ❖ Individual aggregate instances can only be accessed through the aggregate root
  • 53. Repositories ❖ A specialised adapter that maps entities to and from the persistence layer! ❖ Provides methods to retrieve entities and save them! ❖ Abstracts the details of the persistence layer away from the domain
  • 54. Domain Services ❖ Encapsulates an operation that is not owned by another part of the domain model! ❖ A good service has three properties:! ❖ Models a domain concept that does not conceptually belong to an entity or value object! ❖ Stateless! ❖ Defined in terms of the domain model
  • 55. Domain Services <?php! ! class MoneyTransfer {! public static function transferBetweenAccounts(Account $from, Account $to, Money $amount) {! $from->debitForTransfer($money, $to);! $to->creditFromTransfer($money, $from);! }! }! ! //In the application service...! $from = $accountRepository->findByAccNumber('123456');! $to = $accountRepository->findByAccNumber('123457');! $money = new Money('100', new Currency('CAD'));! MoneyTransfer::transferBetweenAccounts($from, $to, $money);!
  • 56. Domain Events ❖ Allows a domain to signal that something as happened! ❖ Full part of the domain and a representation of something that has happened! ❖ Used to signal something that might trigger a state change in another domain
  • 57. Domain Events <?php! ! class MoneyTransfer {! public static function transferBetweenAccounts(Account $from, Account $to, Money $amount) {! $from->debitForTransfer($money, $to);! $to->creditFromTransfer($money, $from);! }! }! ! //In the application service...! $from = $accountRepository->findByAccNumber('123456');! $to = $accountRepository->findByAccNumber('123457');! $money = new Money('100', new Currency('CAD'));! MoneyTransfer::transferBetweenAccounts($from, $to, $money);! $event = EventFactory::createEventForSuccessfulAccountTransfer($from, $to, $money);! $eventType = EventTypes::SUCCESSFUL_MONEY_TRANSFER;! $eventDispatcher->raiseEvent($eventType, $event);
  • 58. Further Information on DDD ❖ Eric Evans! ❖ “Domain Driven Design” book! ❖ Short introduction: https://domainlanguage.com/ddd/ patterns/DDD_Reference_2011-01-31.pdf! ❖ Implementing Domain Driven Design by Vaughn Vernon! ❖ Mathias Verraes: http://verraes.net! ❖ DDD in PHP Google Group: https://groups.google.com/ forum/#!forum/dddinphp
  • 60. Thanks for listening! ❖ Any questions?! ❖ Feel free to contact me! ❖ jeremycook0@gmail.com! ❖ @JCook21