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

DDD

 DDD

Talk given by Jefersson Nathan (@malukenho) at PHP Experience 2017

Jefersson Nathan

March 27, 2017
Tweet

More Decks by Jefersson Nathan

Other Decks in Programming

Transcript

  1. DDD

  2. @malukenho

  3. None
  4. DDD É PRA MIM?

  5. None
  6. Quantos livros é preciso ler para entender um livro?

  7. None
  8. FILOSOFIA

  9. Tackling Complexity

  10. Heart of Software

  11. Core Domain

  12. Auth Core Domain

  13. Domain

  14. None
  15. Modelo

  16. Domain Model

  17. None
  18. Você tem que estar mortalmente interessado, no problema que está

    envolvido.
  19. “Yo soy yo y mi circunstancia.” Ortega y Gasset

  20. Problemas de comunicação

  21. None
  22. Ubiquitous Language

  23. Literate Programming

  24. When Given Then

  25. Scenario: Buying a single product under £10 Given there is

    a "Sith Lord Lightsaber", which costs £5 When I add the "Sith Lord Lightsaber" to the basket Then I should have 1 product in the basket And the overall basket price should be £9
  26. STATUS QUAESTIONIS

  27. Ninguém pode dar o que não tem.

  28. BBoM

  29. is_array($object); 22,748,480

  30. Event Storming

  31. VALUE OBJECT

  32. ATOMIC STEP

  33. SELF VALIDATED

  34. <?php
 
 declare(strict_types=1);
 
 final class Email
 {
 private $email;


    
 private function __construct(string $email)
 { Assert::isValidEmail($email); 
 $this->email = $email;
 }
 
 public static function fromString(string $email) : self
 {
 return new self($email);
 }
 }
  35. new User('malukenho', 5);

  36. NAMED CONSTRUCTOR

  37. User::fromNameAndFingersByHand( 'malukenho', 5 );

  38. <?php
 
 declare(strict_types=1);
 
 final class RegisterUser
 {
 private $username;


    
 private function __construct(string $username)
 {
 $this->username = $username;
 }
 
 public static function fromString(string $username) : self
 {
 return new self($username);
 } public static function fromUser(User $user) : self
 {
 return new self($user->getUsername());
 }
 }
  39. ANEMIC DOMAIN

  40. IMMUTABLE

  41. Potentially mutable operation

  42. Money Pattern

  43. <?php
 
 declare(strict_types=1); final class Money { public function __construct(int

    $amount, Currency $currency) { $this->amount = $amount; $this->currency = $currency; } }
  44. <?php
 
 declare(strict_types=1); final class Money { public function increaseAmountBy(int

    $amount) : self { return new self( $this->amount() + $amount, $this->currency() ); } }
  45. Entidades

  46. *Identidade

  47. UUID

  48. 
 Uuid::uuid4(); // 7b733ff1-42d2-4638-b7bd-411997c32b11 Value Object

  49. EVITAR INVALID STATE DA ENTIDADE

  50. INDEPENDE DE STORAGE

  51. #TIPS

  52. PERSISTÊNCIA ORM

  53. NÃO USE ANNOTATIONS

  54. Delivery Mechanism

  55. DDD É PRA MIM?

  56. Sylius

  57. PERGUNTAS?

  58. THANKS! @malukenho