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

Domain Driven Design for Mere Mortals

Domain Driven Design for Mere Mortals

Application architecture can seem like a buzzword. In this talk we will look at some useful, fundamental concepts introduced by the book on Domain Driven Design and how we as PHP developers can apply these techniques to our applications. Walking out of this talk you should have a functional understanding of how to approach designing how your applications execute business logic using DDD patterns and processes.

Jeff Carouth

April 25, 2014
Tweet

More Decks by Jeff Carouth

Other Decks in Programming

Transcript

  1. What is Domain Driven Design? A collection of patterns and

    principles which help developers craft elegant software.
  2. disclaimer #1 Domain Driven Design was created to solve complicated

    problems. As such there is no way to learn it in one hour, one talk, or one deep thought.
  3. Disclaimer #2 There are a lot of very complicated domains

    which would be served well by using DDD. There are many more that would not.
  4. The Ubiquitous Language A common language shared between business and

    developers which is understood to mean the same things, and, more importantly, is framed in business terminology rather than technical terminology.
  5. The Ubiquitous Language consists of mainly words and expressions that

    are understood by both business experts and developers.
  6. bounded context A Bounded Context is an area of your

    application that is bounded by explicit boundaries and has its own Model and maintains its own code.
  7. Context Maps Bounded Context must sometimes communicate with each other.

    A Context Map is the contract your Bounded Context agrees to fulfill with the outside world.
  8. class BankAccount! {! private $accountNumber;! private $routingNumber;! private $customerName;! private

    $customerEmail;! ! public function setAccountNumber($number)! {! $this->accountNumber = $number;! }! ! public function setRoutingNumber($number)! {! $this->accountNumber = $number;! }! }!
  9. class AccountNumber! {! public function construct($routingNumber, $accountNumber)! {! //...snip...! }!

    }! ! class BankAccount! {! private $accountNumber;! private $customer;! ! public function __construct(AccountNumber $accountNumber, ! Customer $customer)! {! $this->accountNumber = $accountNumber;! $this->customer = $customer;! }! }
  10. Value Objects An object that holds value within its state,

    but is indistinguishable from other objects of the same type with the same attributes.
  11. class Money! {! public function __construct($value, $currency)! {! //...snip...! }!

    }! ! $fiveDollars = new Money(5, 'USD');! $anotherFiveDollars = new Money(5, 'USD');
  12. class Customer! {! public function __construct($billingAddress, $email)! {! if (!/*

    nasty email regex here*/) {! throw new \InvalidArgumentException('message');! }! }! }!
  13. class Email! {! public function __construct($name)! {! if (!/* nasty

    email regex here*/) {! throw new \InvalidArgumentException('message');! }! $this->email = $email;! }! }! ! class Customer! {! public function __construct($billingAddress, Email $email)! {! $this->billingAddress = $billingAddress;! $this->email = $email;! }! }
  14. class Order! {! /** @var string */! private $orderId;! !

    /** @var Customer */! private $customer;! ! /** @var Product */! private $product;! ! /** @var PaymentStatus */! private $paymentStatus;! ! /** @var OrderLines[] */! private $lineItems;! }
  15. Repositories An abstraction for persistence. A Repository can be thought

    of as an interface representing an in-memory data store for Entities or Aggregates.
  16. interface CustomerRepository! {! public function add(Customer $customer);! ! public function

    remove(Customer $customer);! ! /** @return Customer */! public function find(CustomerId $customerId);! ! /** @return array */! public function findAll();! }
  17. Recap • DDD is a set of patterns and practices

    which help deal with business complexity in the Domain.
  18. Recap • DDD is a set of patterns and practices

    which help deal with business complexity in the Domain. • DDD is not necessarily the right fit for every project.
  19. Recap • DDD is a set of patterns and practices

    which help deal with business complexity in the Domain. • DDD is not necessarily the right fit for every project. • DDD wants you to think in Contexts.
  20. Recap • DDD is a set of patterns and practices

    which help deal with business complexity in the Domain. • DDD is not necessarily the right fit for every project. • DDD wants you to think in Contexts. • DDD has building blocks that help with the implementation of your Domain Model.
  21. Resources Domain Driven Design by Eric Evans is the original,

    more academic look into DDD. Implementing Domain Driven Design by Vaughn Vernon has a more practical approach to teaching DDD.
  22. DDDinPHP Google Group Resources The Dev Book Club is reading

    and discussing the IDDD book. Discussion group focusing on applying DDD to PHP projects. devbookclub.org dddinphp.org