SlideShare a Scribd company logo
1 of 59
Download to read offline
DDD on example of Symfony 
Oleg ZInchenko 
1cdecoder@gmail.com
cystbear 
Symfony expert 
MongoDB adept 
Erlang fun 
OSS doer 
KNPer 
https://twitter.com/1cdecoder 
https://github.com/cystbear 
http://knplabs.com/
What this talk about?
About useful tool/lib?
About success story?
No! It’s about idea 
Motivation!
MVC
Where to store business logic? 
Model 
View 
Controller
Where to store business logic? 
Model 
View 
Controller
Where to store business logic? 
Model 
View 
Controller
Where to store business logic? 
Model 
View 
Controller -- YEAH!
Welcome to 
Fat Stupid Ugly Controllers 
FSUC/FUC 
http://blog.astrumfutura.com/2008/12/the-m-in-mvc-why-models-are-misunderstood-and-unappreciated/ 
http://zendframework.ru/anonses/model-with-mvc 
http://habrahabr.ru/post/175465/
Anemic (Domain) Model 
“In essence the problem with anemic domain 
models is that they incur all of the costs of a domain 
model, without yielding any of the benefits.” 
Martin Fowler 
http://www.martinfowler.com/bliki/AnemicDomainModel.html 
http://habrahabr.ru/post/224879/
Model 
Persistence Layer
What is 
Not MVC (phew!) 
Request / Response Framework 
HTTP Framework 
http://fabien.potencier.org/article/49/what-is-symfony2
What about model, 
persistence layer?
Meet Doctrine 
http://www.doctrine-project.org/ 
SQL -- DBAL + ORM 
MongoDB 
CouchDB 
OrientDB 
PHPCR ODM 
OXM
http://www.martinfowler.com/articles/injection.html 
http://fabien.potencier.org/article/11/what-is-dependency-injection 
http://fabien.potencier.org/article/13/introduction-to-the-symfony-service-container
Services 
http://groovy.codehaus.org/ 
https://grails.org/ 
Single Class 
With its Deps (min) set 
Easy to Replace 
Easy to Test 
MVC(S)!
Controller’s pray 
https://twitter.com/ornicar 
Get Request 
Submit form if any 
Call one Service method 
Return Response 
Rendering HTML far away
Managers Managers Managers 
http://blog.codinghorror.com/i-shall-call-it-somethingmanager/ 
http://stackoverflow.com/questions/1866794/naming-classes-how-to-avoid- 
calling-everything-a-whatevermanager 
<SmtManager> 
<WhatEverManager> 
<MyManager> 
<EtcManager>
Real Pain 
class BackendUserProgramsPossessionFormHandler 
{ 
protected $dep1; // deps holder props 
public function __construct(DepsClass $dep1 /*, ...*/) 
{ 
$this->dep1 = $dep1; 
} 
public function process(Form $form) 
{ 
$this->dep1->makeHappy($form); 
// ... 
}
How Kris writes Symfony apps#44 
https://twitter.com/kriswallsmith 
http://www.slideshare.net/kriswallsmith/how-kris-writessymfonyapps
How Kris writes Symfony apps#44 
https://twitter.com/kriswallsmith 
http://www.slideshare.net/kriswallsmith/how-kris-writessymfonyapps
Just A Thought 
https://twitter.com/mr_r_miller/status/522343384900718592
Domain Logic Patterns 
http://martinfowler.com/books/eaa.html
Domain Logic Patterns 
http://martinfowler.com/books/eaa.html 
Transaction Script 
Domain Model 
Table Module 
Service Layer
Transaction Script
Domain Model
Table Module
Domain Logic 
& 
Application logic
Service Layer
What is next? 
RAD 
DDD Patterns 
Examples 
Layers 
Goodies
DDD != RAD 
Code First 
Do not Care about persistence (yet)
Patterns & Code 
Domain Model 
Repository 
Value Object 
DTO 
Strategy 
State
Domain Model
Domain Model 
<?php 
namespace MegaCorpCoreProduct; 
class Product 
{ 
private $id; 
private $name; 
private $recognitionStrategy; 
public function __construct( 
ProductId $id, $name, $recognitionStrategy 
) { 
$this->id = $id; 
$this->name = $name; 
$this->recognitionStrategy = $recognitionStrategy; 
}
Repository 
<?php 
namespace MegaCorpCoreProduct; 
interface ProductRepository 
{ 
public function find(ProductId $productId); 
public function findAll(); 
public function add(Product $product); 
public function remove(Product $product); 
}
Value Object 
<?php 
namespace MegaCorpCore; 
class ProductId 
{ 
private $value; 
public function __construct($value) 
{ 
$this->value = (string) $value; 
} 
public function getValue() 
{ 
return $this->value; 
} 
}
Value Object DateRange
Value Object DateRange 
<?php 
public function findByDateRange( 
DateTime $from, DateTime $to ) 
class DateRange 
{ 
private $from; 
private $to; 
public function __construct(DateTime $from, DateTime $to) 
{ 
$this->from = $from; 
$this->to = $to; 
} 
} 
public function findByDateRange(DateRange $range)
Value Object Money
<?php 
class Money 
{ 
private $amount; 
private $currency; 
public function __construct( 
$amount, 
Currency $currency 
) { 
// ... 
} 
} 
Value Object Money
<?php 
class ProfileData 
{ 
public $firstName; 
public $lastName; 
public $birthday; 
} 
DTO
Strategy
______ ______ _______ _______ 
/ | / __  |  | ____| 
| ,----'| | | | | .--. || |__ 
| | | | | | | | | || __| 
| `----.| `--' | | '--' || |____ 
______| ______/ |_______/ |_______|
src 
└── MegaCorp 
Directory structure 
├── ApiBundle 
│ ├── Controller 
│ │ └── ... 
│ └── MegaCorpApiBundle.php 
├── Core 
│ └── Product 
│ ├── Product.php 
│ ├── ProductId.php 
│ └── ProductRepository.php 
└── CoreBundle 
├── Controller 
│ └── ... 
├── Repository 
│ ├── InMemoryProductRepository.php 
│ └── MongoDbProductRepository.php 
└── MegaCorpCoreBundle.php
Layers
Layers 
Domain Layer -- heart of your application, Entities and Repositories 
Application Layer -- Controllers 
Presentation Layer -- Templates / DTOs for serializer 
Infrastructure Layer -- framework, persistence, concrete 
implementations of Domain Layer
Useful goodies
BBB DDD by Eric Evans 
http://amzn.com/0321125215/
DDD Quickly by InfoQ 
http://www.infoq.com/minibooks/domain-driven-design-quickly
PoEAA by Martin Fowler 
http://amzn.com/B008OHVDFM/
DDD and Patterns by Jimmy Nilsson 
http://amzn.com/B0054KOKQQ/
Links 
http://dddcommunity.org/ 
http://williamdurand.fr/ 
http://welcometothebundle.com/ 
http://verraes.net/ 
http://jimmynilsson.com/blog/ 
http://www.martinfowler.com/ 
http://elephantintheroom.io/ -- podcast 
http://msdn.microsoft.com/en-us/magazine/dd419654.aspx 
http://www.martinfowler.com/bliki/AnemicDomainModel.html 
http://martinfowler.com/bliki/CQRS.html
Thanks!

More Related Content

What's hot

オブジェクト指向エクササイズのススメ
オブジェクト指向エクササイズのススメオブジェクト指向エクササイズのススメ
オブジェクト指向エクササイズのススメ
Yoji Kanno
 
If You Think You Can Stay Away from Functional Programming, You Are Wrong
If You Think You Can Stay Away from Functional Programming, You Are WrongIf You Think You Can Stay Away from Functional Programming, You Are Wrong
If You Think You Can Stay Away from Functional Programming, You Are Wrong
Mario Fusco
 

What's hot (20)

Towards Functional Programming through Hexagonal Architecture
Towards Functional Programming through Hexagonal ArchitectureTowards Functional Programming through Hexagonal Architecture
Towards Functional Programming through Hexagonal Architecture
 
Railway Oriented Programming
Railway Oriented ProgrammingRailway Oriented Programming
Railway Oriented Programming
 
モナドハンズオン前座
モナドハンズオン前座モナドハンズオン前座
モナドハンズオン前座
 
DDD with Behat
DDD with BehatDDD with Behat
DDD with Behat
 
Dapper performance
Dapper performanceDapper performance
Dapper performance
 
Scalability, Availability & Stability Patterns
Scalability, Availability & Stability PatternsScalability, Availability & Stability Patterns
Scalability, Availability & Stability Patterns
 
オブジェクト指向エクササイズのススメ
オブジェクト指向エクササイズのススメオブジェクト指向エクササイズのススメ
オブジェクト指向エクササイズのススメ
 
If You Think You Can Stay Away from Functional Programming, You Are Wrong
If You Think You Can Stay Away from Functional Programming, You Are WrongIf You Think You Can Stay Away from Functional Programming, You Are Wrong
If You Think You Can Stay Away from Functional Programming, You Are Wrong
 
Using VueJS in front of Drupal 8
Using VueJS in front of Drupal 8Using VueJS in front of Drupal 8
Using VueJS in front of Drupal 8
 
Domain Driven Design with the F# type System -- F#unctional Londoners 2014
Domain Driven Design with the F# type System -- F#unctional Londoners 2014Domain Driven Design with the F# type System -- F#unctional Londoners 2014
Domain Driven Design with the F# type System -- F#unctional Londoners 2014
 
Production-ready GraphQL with Caliban
Production-ready GraphQL with CalibanProduction-ready GraphQL with Caliban
Production-ready GraphQL with Caliban
 
[PHPConf Taiwan 2015] 跟著 Laravel 5.1 一起成為更好的 PHP 開發者
[PHPConf Taiwan 2015] 跟著 Laravel 5.1 一起成為更好的 PHP 開發者[PHPConf Taiwan 2015] 跟著 Laravel 5.1 一起成為更好的 PHP 開發者
[PHPConf Taiwan 2015] 跟著 Laravel 5.1 一起成為更好的 PHP 開發者
 
Nodejs functions & modules
Nodejs functions & modulesNodejs functions & modules
Nodejs functions & modules
 
DDD Tactical Design with Clean Architecture - Ivan Paulovich
DDD Tactical Design with Clean Architecture - Ivan PaulovichDDD Tactical Design with Clean Architecture - Ivan Paulovich
DDD Tactical Design with Clean Architecture - Ivan Paulovich
 
Scalable JavaScript Application Architecture
Scalable JavaScript Application ArchitectureScalable JavaScript Application Architecture
Scalable JavaScript Application Architecture
 
入門Transducers
入門Transducers入門Transducers
入門Transducers
 
Domain Modeling with FP (DDD Europe 2020)
Domain Modeling with FP (DDD Europe 2020)Domain Modeling with FP (DDD Europe 2020)
Domain Modeling with FP (DDD Europe 2020)
 
Models and Service Layers, Hemoglobin and Hobgoblins
Models and Service Layers, Hemoglobin and HobgoblinsModels and Service Layers, Hemoglobin and Hobgoblins
Models and Service Layers, Hemoglobin and Hobgoblins
 
Eloquent ORM
Eloquent ORMEloquent ORM
Eloquent ORM
 
Ruby from zero to hero
Ruby from zero to heroRuby from zero to hero
Ruby from zero to hero
 

Viewers also liked

Domain Driven Design - как, почему и зачем?
Domain Driven Design - как, почему и зачем?Domain Driven Design - как, почему и зачем?
Domain Driven Design - как, почему и зачем?
ngrebnev
 
A Guide to SlideShare Analytics - Excerpts from Hubspot's Step by Step Guide ...
A Guide to SlideShare Analytics - Excerpts from Hubspot's Step by Step Guide ...A Guide to SlideShare Analytics - Excerpts from Hubspot's Step by Step Guide ...
A Guide to SlideShare Analytics - Excerpts from Hubspot's Step by Step Guide ...
SlideShare
 

Viewers also liked (13)

Применение DDD подхода в Symfony 2 приложении
Применение DDD подхода в Symfony 2 приложенииПрименение DDD подхода в Symfony 2 приложении
Применение DDD подхода в Symfony 2 приложении
 
Основы доменной модели
Основы доменной моделиОсновы доменной модели
Основы доменной модели
 
Domain Driven Design - как, почему и зачем?
Domain Driven Design - как, почему и зачем?Domain Driven Design - как, почему и зачем?
Domain Driven Design - как, почему и зачем?
 
DDD - модель вместо требований
DDD - модель вместо требованийDDD - модель вместо требований
DDD - модель вместо требований
 
Decoupling the Ulabox.com monolith. From CRUD to DDD
Decoupling the Ulabox.com monolith. From CRUD to DDDDecoupling the Ulabox.com monolith. From CRUD to DDD
Decoupling the Ulabox.com monolith. From CRUD to DDD
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Enterprise PHP: mappers, models and services
Enterprise PHP: mappers, models and servicesEnterprise PHP: mappers, models and services
Enterprise PHP: mappers, models and services
 
reveal.js 3.0.0
reveal.js 3.0.0reveal.js 3.0.0
reveal.js 3.0.0
 
A Guide to SlideShare Analytics - Excerpts from Hubspot's Step by Step Guide ...
A Guide to SlideShare Analytics - Excerpts from Hubspot's Step by Step Guide ...A Guide to SlideShare Analytics - Excerpts from Hubspot's Step by Step Guide ...
A Guide to SlideShare Analytics - Excerpts from Hubspot's Step by Step Guide ...
 
2015 Upload Campaigns Calendar - SlideShare
2015 Upload Campaigns Calendar - SlideShare2015 Upload Campaigns Calendar - SlideShare
2015 Upload Campaigns Calendar - SlideShare
 
What to Upload to SlideShare
What to Upload to SlideShareWhat to Upload to SlideShare
What to Upload to SlideShare
 
How to Make Awesome SlideShares: Tips & Tricks
How to Make Awesome SlideShares: Tips & TricksHow to Make Awesome SlideShares: Tips & Tricks
How to Make Awesome SlideShares: Tips & Tricks
 
Getting Started With SlideShare
Getting Started With SlideShareGetting Started With SlideShare
Getting Started With SlideShare
 

Similar to DDD on example of Symfony (SfCampUA14)

DDD on example of Symfony (Webcamp Odessa 2014)
DDD on example of Symfony (Webcamp Odessa 2014)DDD on example of Symfony (Webcamp Odessa 2014)
DDD on example of Symfony (Webcamp Odessa 2014)
Oleg Zinchenko
 
Construction Techniques For Domain Specific Languages
Construction Techniques For Domain Specific LanguagesConstruction Techniques For Domain Specific Languages
Construction Techniques For Domain Specific Languages
ThoughtWorks
 
Hanoi php day 2008 - 01.pham cong dinh - how.to.build.your.own.framework
Hanoi php day 2008 - 01.pham cong dinh - how.to.build.your.own.frameworkHanoi php day 2008 - 01.pham cong dinh - how.to.build.your.own.framework
Hanoi php day 2008 - 01.pham cong dinh - how.to.build.your.own.framework
Nguyen Duc Phu
 
Speed up your developments with Symfony2
Speed up your developments with Symfony2Speed up your developments with Symfony2
Speed up your developments with Symfony2
Hugo Hamon
 
Intro To Mvc Development In Php
Intro To Mvc Development In PhpIntro To Mvc Development In Php
Intro To Mvc Development In Php
funkatron
 
Porting Rails Apps to High Availability Systems
Porting Rails Apps to High Availability SystemsPorting Rails Apps to High Availability Systems
Porting Rails Apps to High Availability Systems
Marcelo Pinheiro
 

Similar to DDD on example of Symfony (SfCampUA14) (20)

WebCamp: Developer Day: DDD in PHP on example of Symfony - Олег Зинченко
WebCamp: Developer Day: DDD in PHP on example of Symfony - Олег ЗинченкоWebCamp: Developer Day: DDD in PHP on example of Symfony - Олег Зинченко
WebCamp: Developer Day: DDD in PHP on example of Symfony - Олег Зинченко
 
DDD on example of Symfony (Webcamp Odessa 2014)
DDD on example of Symfony (Webcamp Odessa 2014)DDD on example of Symfony (Webcamp Odessa 2014)
DDD on example of Symfony (Webcamp Odessa 2014)
 
Construction Techniques For Domain Specific Languages
Construction Techniques For Domain Specific LanguagesConstruction Techniques For Domain Specific Languages
Construction Techniques For Domain Specific Languages
 
RubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - KeynoteRubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - Keynote
 
How to learn to build your own PHP framework
How to learn to build your own PHP frameworkHow to learn to build your own PHP framework
How to learn to build your own PHP framework
 
Hanoi php day 2008 - 01.pham cong dinh - how.to.build.your.own.framework
Hanoi php day 2008 - 01.pham cong dinh - how.to.build.your.own.frameworkHanoi php day 2008 - 01.pham cong dinh - how.to.build.your.own.framework
Hanoi php day 2008 - 01.pham cong dinh - how.to.build.your.own.framework
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
Speed up your developments with Symfony2
Speed up your developments with Symfony2Speed up your developments with Symfony2
Speed up your developments with Symfony2
 
Intro To Mvc Development In Php
Intro To Mvc Development In PhpIntro To Mvc Development In Php
Intro To Mvc Development In Php
 
Finding Your Way: Understanding Magento Code
Finding Your Way: Understanding Magento CodeFinding Your Way: Understanding Magento Code
Finding Your Way: Understanding Magento Code
 
Sinatra and friends
Sinatra and friendsSinatra and friends
Sinatra and friends
 
Framework Presentation
Framework PresentationFramework Presentation
Framework Presentation
 
Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018
 
Hexagonal architecture in PHP
Hexagonal architecture in PHPHexagonal architecture in PHP
Hexagonal architecture in PHP
 
Doctrine with Symfony - SymfonyCon 2019
Doctrine with Symfony - SymfonyCon 2019Doctrine with Symfony - SymfonyCon 2019
Doctrine with Symfony - SymfonyCon 2019
 
So S.O.L.I.D Fu - Designing Better Code
So S.O.L.I.D Fu - Designing Better CodeSo S.O.L.I.D Fu - Designing Better Code
So S.O.L.I.D Fu - Designing Better Code
 
Porting Rails Apps to High Availability Systems
Porting Rails Apps to High Availability SystemsPorting Rails Apps to High Availability Systems
Porting Rails Apps to High Availability Systems
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applications
 
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
 
Streamlining Your Applications with Web Frameworks
Streamlining Your Applications with Web FrameworksStreamlining Your Applications with Web Frameworks
Streamlining Your Applications with Web Frameworks
 

More from Oleg Zinchenko (7)

Oro meetup #4
Oro meetup #4Oro meetup #4
Oro meetup #4
 
Keep It Simple Security (Symfony cafe 28-01-2016)
Keep It Simple Security (Symfony cafe 28-01-2016)Keep It Simple Security (Symfony cafe 28-01-2016)
Keep It Simple Security (Symfony cafe 28-01-2016)
 
Erlang (GeekTalks)
Erlang (GeekTalks)Erlang (GeekTalks)
Erlang (GeekTalks)
 
Welcome to Erlang
Welcome to ErlangWelcome to Erlang
Welcome to Erlang
 
Erlang/N2O at KNPMeetup 2015
Erlang/N2O at KNPMeetup 2015Erlang/N2O at KNPMeetup 2015
Erlang/N2O at KNPMeetup 2015
 
PHP. Trends, implementations, frameworks and solutions
PHP. Trends, implementations, frameworks and solutionsPHP. Trends, implementations, frameworks and solutions
PHP. Trends, implementations, frameworks and solutions
 
Введение в REST API
Введение в REST APIВведение в REST API
Введение в REST API
 

DDD on example of Symfony (SfCampUA14)