introduction to domain driven design (laravelba #5)
DESCRIPTION
Introduction to Domain driven design, given by @GuiWoda at #LaravelBA on sept 17, 2014TRANSCRIPT
![Page 1: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/1.jpg)
Domain Driven Design
![Page 2: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/2.jpg)
Ubiquitous Language
UbiquitousLanguage@Fowler's blog
![Page 3: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/3.jpg)
Ubiquitous LanguageThat’s all there is to it
![Page 4: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/4.jpg)
Ubiquitous LanguageThat’s all there is to it
Questions?
![Page 5: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/5.jpg)
Client (Domain expert)
Project Manager Developer
We need to add a new security policy to our
accounts. Our customers can’t have more than two
active offers per billing term.
We need to restrict promotions. A user cannot
have more than two promotions per month.
public function validate(User $user){ // … other crazy validations
if (count ($user->getPromotions()) > 2) throw new ValidationException( “User can’t have more than 2 promotions per month” );
// … continue with crazy validations}
![Page 6: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/6.jpg)
Favor model language over translations
![Page 7: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/7.jpg)
Client (Domain expert)
Project Manager Developer
We need to add a new security policy to our
accounts. Our customers can’t have more than two
active offers per billing term.
public function validate(Account $account){ // … other crazy validations
if (! $account->satisfies( new ActiveOffersPerBillingTermSecurityPolicy )) throw new ValidationException( “Account did not satisfy the active offers security policy” );
// … continue with crazy validations}
![Page 8: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/8.jpg)
ActiveOffersPerBillingTermSecurityPolicy
… really?TOO MUCH CODE!
I WON’T TYPE THAT!!!11
![Page 9: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/9.jpg)
Semantics
![Page 10: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/10.jpg)
SemanticsActiveOffersPerBillingTermSecurityPolicy means something
in the MODEL LANGUAGE
count($user->getPromotions()) > 2 does not convey this knowledge
![Page 11: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/11.jpg)
SemanticsActiveOffersPerBillingTermSecurityPolicy means something
in the MODEL LANGUAGE
count($user->getPromotions()) > 2 does not convey this knowledge
=> MAKE IMPLICIT BUSINESS RULES EXPLICIT
![Page 12: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/12.jpg)
Favor model language over translations
When a domain expert (client) feels something’s wrong with the model language, you’ll know something’s wrong with the domain model.
![Page 13: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/13.jpg)
Client (Domain expert)
Project Manager Developer
When we talk about a billing term, we need to consider if the customer is billed on a
monthly or yearly basis.
| class ActiveOffersPerBillingTermSecurityPolicy | { | protected $maxOffers = 2; | | public function isSatisfiedBy(Account $account) | { | return count(- | $account->getMonthlyOffers()+ | $account->getOffersForBillingTerm() | ) < $this->maxOffers; | }
![Page 14: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/14.jpg)
Domain Knowledge
![Page 15: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/15.jpg)
Domain KnowledgeFocus your efforts in building a clear domain,
specific to your client’s needs
![Page 16: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/16.jpg)
Knowledge crunching
![Page 17: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/17.jpg)
Client (Domain expert)
Project Manager Developer
class LongOverdueCustomerContactCommand{ public function execute() { $customers = Customer::where( ‘account.balance’, ‘<’, 0 )->get();
foreach ($customers as $customer) $this->sendRefinanceEmail($customer); }}
We need to contact long overdue customers to refinance their debt.
![Page 18: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/18.jpg)
Client (Domain expert)
Project Manager Developer
class LongOverdueCustomerContactCommand{ public function execute() { $customers = Customer::where( ‘account.balance’, ‘<’, 0 )->get();
foreach ($customers as $customer) $this->sendRefinanceEmail($customer); }}
We need to contact long overdue customers to refinance their debt.
![Page 19: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/19.jpg)
Client (Domain expert)
Project Manager Developer
We need to contact long overdue customers to refinance their debt.
What is the difference between a regular customer, an overdue customer and a
long overdue customer?
![Page 20: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/20.jpg)
Client (Domain expert)
Project Manager Developer
class CustomerRepository{ public function findOverdue() { return Customer::where(‘account.balance’, ‘<’, 0) ->get(); }
public function findLongOverdue() { // Write more complex query logic for this one... }}
Overdue is straightforward, customers in debt right now.
Long overdue customers are the ones that have been overdue over the last 3
billing terms, at the end of each billing term.
![Page 21: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/21.jpg)
Knowledge crunchingKnowledge crunching deepens the domain
model, and brings better understanding
![Page 22: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/22.jpg)
But… How?
![Page 23: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/23.jpg)
Domain-orientedDesign Patterns
![Page 24: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/24.jpg)
class AccountsController{ public function index() { $accounts = Account::all();
return View::make(‘accounts.index’, [ ‘accounts’ => $accounts ]); }}
![Page 25: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/25.jpg)
class AccountsController{ public function index() { $accounts = Account::all();
return View::make(‘accounts.index’, [ ‘accounts’ => $accounts ]); }}
![Page 27: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/27.jpg)
Entities
![Page 28: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/28.jpg)
EntitiesObjects with an identity
LifespanUnique criteria
![Page 29: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/29.jpg)
ValueObjects
![Page 30: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/30.jpg)
ValueObjectsDefined by their attributes
![Page 31: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/31.jpg)
Aggregates
![Page 32: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/32.jpg)
AggregatesCluster of domain objectsTransactional coherence
![Page 33: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/33.jpg)
Services
![Page 34: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/34.jpg)
ServicesDomain coordinators
Define actions
![Page 35: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/35.jpg)
Repositories
![Page 36: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/36.jpg)
RepositoriesData access abstraction
![Page 37: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/37.jpg)
Factories
![Page 38: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/38.jpg)
FactoriesObject creation
![Page 39: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/39.jpg)
Domain Events
![Page 40: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/40.jpg)
Domain EventsObjects that represent significant domain
events
![Page 41: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/41.jpg)
Domain-orientedArchitecture
![Page 42: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/42.jpg)
Layered Architecture
![Page 43: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/43.jpg)
Layered Architecture
?
![Page 44: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/44.jpg)
Hexagonal Architecture
![Page 45: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/45.jpg)
Hexagonal Architecture
?
![Page 46: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/46.jpg)
Domain-orientedArchitecture
Isolate your domain model from specific application needs:
UI - Persistence - External Services - Application workflow - etc...
![Page 47: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/47.jpg)
So… What’s the point?
![Page 48: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/48.jpg)
It’s not about writing code
![Page 49: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/49.jpg)
It’s not about writing codeThat’s the easy part… right?
![Page 50: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/50.jpg)
It’s not about writing codeIt’s about understanding what needs to be
solved before starting to code
![Page 51: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/51.jpg)
Creating a language which makes conversations
between domain experts and developers possible without
misinterpretations
![Page 52: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/52.jpg)
Creating a language which makes conversations
between domain experts and developers possible without
(so many) misinterpretations
![Page 53: Introduction to Domain driven design (LaravelBA #5)](https://reader033.vdocuments.mx/reader033/viewer/2022061120/546c3b17af79596b708b4c2c/html5/thumbnails/53.jpg)
● Eric Evans, “Domain-Driven Design: Tackling Complexity in the Heart of Software”
● Vaughn Vernon, “Implementing Domain-Driven Design”
● Martin Fowler, “Patterns of Enterprise Application Architecture”
● dddcommunity.org | Domain Driven Design Community
● -http://domainlanguage.com/ddd/reference/DDD_Reference_2011-01-31.pdf
● -http://www.lmgtfy.com/?q=Domain+Driven+Design