Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
DDD on example of Symfony (SymfonyCamp UA 2014)
Search
Oleg Zinchenko
November 02, 2014
Programming
3
910
DDD on example of Symfony (SymfonyCamp UA 2014)
How I realized that MVC is a myth and why MVC duped us for a years.
Oleg Zinchenko
November 02, 2014
Tweet
Share
More Decks by Oleg Zinchenko
See All by Oleg Zinchenko
ORO Meetup #4
cystbear
0
80
Keep It Simple Security (Symfony Cafe 28-01-2016)
cystbear
0
120
Erlang (GeekTalks)
cystbear
0
74
Clojure basics
cystbear
0
82
Welcome to Erlang
cystbear
0
83
Erlang/N2O KNPMeetup
cystbear
0
160
Symfony Best Practices and beyond
cystbear
1
230
MongoDB KNPLabs GeekTime
cystbear
1
79
DDD in PHP, on example of Symfony
cystbear
10
4.1k
Other Decks in Programming
See All in Programming
Stackless и stackful? Корутины и асинхронность в Go
lamodatech
0
1.2k
htmxって知っていますか?次世代のHTML
hiro_ghap1
0
400
shadcn/uiを使ってReactでの開発を加速させよう!
lef237
0
240
どうして手を動かすよりもチーム内のコードレビューを優先するべきなのか
okashoi
3
820
PHPで作るWebSocketサーバー ~リアクティブなアプリケーションを知るために~ / WebSocket Server in PHP - To know reactive applications
seike460
PRO
2
720
선언형 UI에서의 상태관리
l2hyunwoo
0
250
ATDDで素早く安定した デリバリを実現しよう!
tonnsama
1
1.2k
PHPカンファレンス 2024|共創を加速するための若手の技術挑戦
weddingpark
0
120
20241217 競争力強化とビジネス価値創出への挑戦:モノタロウのシステムモダナイズ、開発組織の進化と今後の展望
monotaro
PRO
0
240
Package Traits
ikesyo
1
150
Androidアプリの One Experience リリース
nein37
0
750
快速入門可觀測性
blueswen
0
480
Featured
See All Featured
BBQ
matthewcrist
85
9.4k
Faster Mobile Websites
deanohume
305
30k
Being A Developer After 40
akosma
89
590k
Scaling GitHub
holman
459
140k
4 Signs Your Business is Dying
shpigford
182
21k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
112
50k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.2k
jQuery: Nuts, Bolts and Bling
dougneiner
62
7.6k
How to Think Like a Performance Engineer
csswizardry
22
1.3k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
2
160
Side Projects
sachag
452
42k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Transcript
DDD on example of Symfony Oleg ZInchenko
[email protected]
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 http://www.martinfowler.com/bliki/AnemicDomainModel.html http://habrahabr.ru/post/224879/ “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
Persistence Layer Model
None
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
https://twitter.com/kriswallsmith http://www.slideshare.net/kriswallsmith/how-kris-writessymfonyapps How Kris writes Symfony apps#44
https://twitter.com/mr_r_miller/status/522343384900718592 Just A Thought
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
None
What is next? RAD DDD Patterns Examples Layers Goodies
DDD != RAD Code First Do not Care about persistence
(yet)
Domain Model Repository Value Object DTO Strategy State Patterns &
Code
Domain Model
Domain Model <?php namespace MegaCorp\Core\Product; 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 MegaCorp\Core\Product; interface ProductRepository { public function find(ProductId
$productId); public function findAll(); public function add(Product $product); public function remove(Product $product); }
Value Object <?php namespace MegaCorp\Core; 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 ├── ApiBundle │ ├── Controller │ │
└── ... │ └── MegaCorpApiBundle.php ├── Core │ └── Product │ ├── Product.php │ ├── ProductId.php │ └── ProductRepository.php └── CoreBundle ├── Controller │ └── ... ├── Repository │ ├── InMemoryProductRepository.php │ └── MongoDbProductRepository.php └── MegaCorpCoreBundle.php Directory structure
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
None
Thanks!