Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Domain-Driven Design

Domain-Driven Design

Talk given at PHP Serbia 2017:
(http://www.conf2017.phpsrbija.rs/)

Andrew Cassell

May 28, 2017
Tweet

More Decks by Andrew Cassell

Other Decks in Technology

Transcript

  1. 12

  2. People don't want to buy a quarter-inch drill, they want

    a quarter-inch hole. Theodore Levitt
  3. 1. Naming Things 2. Cache Invalidation 3. Off By One

    Errors Top 10 Reasons Programming is Hard
  4. $user = User::findOrFail($uuid);
 $book = Books::where('isbn', '=', $isbn)->take(1)->get();
 
 


    if (!$user->userBookLinks()->contains($book->id) && $user->borrowLinks->count() < 5) {
 
 $user->userBookLinks()->attach($book->id, ['date_due' => new DateTime('+2 Weeks')];
 
 }
 
 
 $user->save();
  5. $catalog = new LibraryCatalog(…); $book = $catalog->findOneBookByISBN($isbn); $members = new

    Members(…); $borrower = $members->findOneByAccountNumber($acctNumber); $borrower->borrow($book);
  6. @library @loan Feature: A member should be able to borrow

    a book Scenario: Member borrows a book Given I am authenticated as a librarian And I am on “/member/behat-123" And I press "Borrow Book" And I fill out form with: | ISBN | | 978-032-112521-7 | Then I see "Domain-driven Design"
  7. @library @loan Feature: A member should be able to borrow

    a book Scenario: Member borrows a book Given I am authenticated as a librarian And I am on “/member/behat-123" And I press "Borrow Book" And I fill out form with: | ISBN | | 978-032-112521-7 | Then I see "Domain-driven Design"
  8. […], we want to establish the idea that a computer

    language is not just a way of getting a computer to perform operations but rather that it is a novel formal medium for expressing ideas about methodology. Thus, programs must be written for people to read, and only incidentally for machines to execute.
  9. 7 Dirty Words When Meeting With a Domain Expert 1.Session

    2.Repository 3.Abstract 4.Interface 5.Class 6.Database 7.Foreign Key
  10. Value Object Immutable No Identity (Only Values) Book Title Amount

    Paid ISBN Number Entity Identifiable Mutable Lifecycle Contains Value Objects Book Librarian Invoice Aggregate Entity Responsible For Child Entities Transaction Boundary Member Library
  11. Plain PHP Objects (POPOs) • Declare Class Properties as Private

    • No Setters • No References to Mutable Objects • Throw Exceptions in Constructor Value Objects
  12. Identifiable Have State and are Mutable Never Invalid State Operate

    Using Value Objects No Security or Permission Checks Storage Agnostic Entities
  13. Mathias Verraes - Decoupling the Model from the Framework at

    Laracon EU 2014 https://www.youtube.com/watch?v=QaIGN_cTcc8
  14. Ruby Midwest 2011 - Keynote: Architecture the Lost Years by

    Robert Martin https://www.youtube.com/watch?v=WpkDN78P884
  15. Domain Events • Part of the Core Domain • Happened

    In The Past • Important Enough To Record (Persist) • Important Enough To Concern Other Bounded Contexts • Immutable Value Objects • Do Not Contain Entities or Other Mutable Objects • Can Be Created in an Entity
  16. • Avoids Data Mapping • Avoids Object-relational Impedance Mismatch •

    Reduces Database Table Counts (Related Tables) • Potentially Reduces Model Counts Event Sourcing
  17. Event Sourcing • Object Properties are Not Persisted • Events

    Are Persisted to Append Only Event Storage
  18. https://joind.in/talk/e8752 DDD Topics Covered •Ubiquitous Language •Event Storming •Modelling •Value

    Objects •Entities •Aggregates •Hexagonal Architecture •CQRS •Event Sourcing