DDD on example of Symfony (SfCampUA14)
-
Upload
oleg-zinchenko -
Category
Documents
-
view
1.604 -
download
4
Transcript of DDD on example of Symfony (SfCampUA14)
![Page 2: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/2.jpg)
cystbearSymfony expert
MongoDB adept
Erlang fun
OSS doer
KNPer
https://twitter.com/1cdecoderhttps://github.com/cystbearhttp://knplabs.com/
![Page 3: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/3.jpg)
What this talk about?
![Page 4: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/4.jpg)
About useful tool/lib?
![Page 5: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/5.jpg)
About success story?
![Page 6: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/6.jpg)
No! It’s about idea
Motivation!
![Page 7: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/7.jpg)
MVC
![Page 8: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/8.jpg)
Where to store business logic?
ModelViewController
![Page 9: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/9.jpg)
Where to store business logic?
ModelViewController
![Page 10: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/10.jpg)
Where to store business logic?
ModelViewController
![Page 11: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/11.jpg)
Where to store business logic?
ModelViewController -- YEAH!
![Page 12: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/12.jpg)
Welcome to
Fat Stupid Ugly ControllersFSUC/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/
![Page 13: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/13.jpg)
Anemic (Domain) Model
http://www.martinfowler.com/bliki/AnemicDomainModel.htmlhttp://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
![Page 14: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/14.jpg)
Persistence Layer
Model
![Page 15: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/15.jpg)
![Page 16: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/16.jpg)
What is
Not MVC (phew!)
Request / Response FrameworkHTTP Framework
http://fabien.potencier.org/article/49/what-is-symfony2
![Page 17: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/17.jpg)
What about model,persistence layer?
![Page 18: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/18.jpg)
Meet Doctrine
http://www.doctrine-project.org/
SQL -- DBAL + ORMMongoDBCouchDBOrientDBPHPCR ODMOXM
![Page 19: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/19.jpg)
http://www.martinfowler.com/articles/injection.htmlhttp://fabien.potencier.org/article/11/what-is-dependency-injection
http://fabien.potencier.org/article/13/introduction-to-the-symfony-service-container
![Page 20: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/20.jpg)
Services
http://groovy.codehaus.org/https://grails.org/
Single ClassWith its Deps (min) setEasy to ReplaceEasy to Test
MVC(S)!
![Page 21: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/21.jpg)
Controller’s pray
https://twitter.com/ornicar
Get RequestSubmit form if anyCall one Service methodReturn Response
Rendering HTML far away
![Page 22: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/22.jpg)
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>
![Page 23: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/23.jpg)
Real Painclass BackendUserProgramsPossessionFormHandler{ protected $dep1; // deps holder props
public function __construct(DepsClass $dep1 /*, ...*/) { $this->dep1 = $dep1; }
public function process(Form $form) { $this->dep1->makeHappy($form); // ... }
![Page 24: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/24.jpg)
How Kris writes Symfony apps#44
https://twitter.com/kriswallsmithhttp://www.slideshare.net/kriswallsmith/how-kris-writessymfonyapps
![Page 25: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/25.jpg)
https://twitter.com/kriswallsmithhttp://www.slideshare.net/kriswallsmith/how-kris-writessymfonyapps
How Kris writes Symfony apps#44
![Page 26: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/26.jpg)
https://twitter.com/mr_r_miller/status/522343384900718592
Just A Thought
![Page 27: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/27.jpg)
Domain Logic Patterns
http://martinfowler.com/books/eaa.html
![Page 28: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/28.jpg)
Domain Logic Patterns
http://martinfowler.com/books/eaa.html
Transaction ScriptDomain ModelTable ModuleService Layer
![Page 29: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/29.jpg)
Transaction Script
![Page 30: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/30.jpg)
Domain Model
![Page 31: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/31.jpg)
Table Module
![Page 32: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/32.jpg)
Domain Logic&
Application logic
![Page 33: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/33.jpg)
Service Layer
![Page 34: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/34.jpg)
![Page 35: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/35.jpg)
What is next?RADDDD PatternsExamplesLayersGoodies
![Page 36: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/36.jpg)
DDD != RADCode FirstDo not Care about persistence (yet)
![Page 37: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/37.jpg)
Domain ModelRepositoryValue ObjectDTOStrategyState
Patterns & Code
![Page 38: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/38.jpg)
Domain Model
![Page 39: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/39.jpg)
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; }
![Page 40: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/40.jpg)
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);}
![Page 41: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/41.jpg)
Value Object<?php
namespace MegaCorp\Core;
class ProductId{ private $value;
public function __construct($value) { $this->value = (string) $value; }
public function getValue() { return $this->value; }}
![Page 42: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/42.jpg)
Value Object DateRange
![Page 43: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/43.jpg)
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)
![Page 44: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/44.jpg)
Value Object Money
![Page 45: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/45.jpg)
<?php
class Money{ private $amount; private $currency;
public function __construct( $amount, Currency $currency ) { // ... }}
Value Object Money
![Page 46: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/46.jpg)
<?php
class ProfileData{ public $firstName; public $lastName; public $birthday;}
DTO
![Page 47: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/47.jpg)
Strategy
![Page 48: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/48.jpg)
______ ______ _______ _______ / | / __ \ | \ | ____|| ,----'| | | | | .--. || |__ | | | | | | | | | || __| | `----.| `--' | | '--' || |____ \______| \______/ |_______/ |_______|
![Page 49: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/49.jpg)
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
![Page 50: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/50.jpg)
Layers
![Page 51: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/51.jpg)
LayersDomain Layer -- heart of your application, Entities and Repositories
Application Layer -- ControllersPresentation Layer -- Templates / DTOs for serializerInfrastructure Layer -- framework, persistence, concrete implementations of Domain Layer
![Page 52: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/52.jpg)
Useful goodies
![Page 53: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/53.jpg)
BBB DDD by Eric Evans
http://amzn.com/0321125215/
![Page 54: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/54.jpg)
DDD Quickly by InfoQ
http://www.infoq.com/minibooks/domain-driven-design-quickly
![Page 55: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/55.jpg)
PoEAA by Martin Fowler
http://amzn.com/B008OHVDFM/
![Page 56: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/56.jpg)
DDD and Patterns by Jimmy Nilsson
http://amzn.com/B0054KOKQQ/
![Page 57: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/57.jpg)
Linkshttp://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.aspxhttp://www.martinfowler.com/bliki/AnemicDomainModel.htmlhttp://martinfowler.com/bliki/CQRS.html
![Page 58: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/58.jpg)
![Page 59: DDD on example of Symfony (SfCampUA14)](https://reader034.fdocuments.in/reader034/viewer/2022052311/558940aad8b42ab05b8b46a8/html5/thumbnails/59.jpg)
Thanks!