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

    View Slide

  2. @malukenho

    View Slide

  3. View Slide

  4. DDD
    É PRA MIM?

    View Slide

  5. View Slide

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

    View Slide

  7. View Slide

  8. FILOSOFIA

    View Slide

  9. Tackling
    Complexity

    View Slide

  10. Heart of
    Software

    View Slide

  11. Core
    Domain

    View Slide

  12. Auth
    Core
    Domain

    View Slide

  13. Domain

    View Slide

  14. View Slide

  15. Modelo

    View Slide

  16. Domain
    Model

    View Slide

  17. View Slide

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

    View Slide

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

    View Slide

  20. Problemas de
    comunicação

    View Slide

  21. View Slide

  22. Ubiquitous
    Language

    View Slide

  23. Literate
    Programming

    View Slide

  24. When
    Given
    Then

    View Slide

  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

    View Slide

  26. STATUS
    QUAESTIONIS

    View Slide

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

    View Slide

  28. BBoM

    View Slide

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

    View Slide

  30. Event
    Storming

    View Slide

  31. VALUE OBJECT

    View Slide

  32. ATOMIC
    STEP

    View Slide

  33. SELF
    VALIDATED

    View Slide


  34. 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);

    }

    }

    View Slide

  35. new User('malukenho', 5);

    View Slide

  36. NAMED
    CONSTRUCTOR

    View Slide

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

    View Slide


  38. 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());

    }

    }

    View Slide

  39. ANEMIC
    DOMAIN

    View Slide

  40. IMMUTABLE

    View Slide

  41. Potentially
    mutable
    operation

    View Slide

  42. Money Pattern

    View Slide


  43. declare(strict_types=1);
    final class Money
    {
    public function __construct(int $amount, Currency $currency)
    {
    $this->amount = $amount;
    $this->currency = $currency;
    }
    }

    View Slide


  44. declare(strict_types=1);
    final class Money
    {
    public function increaseAmountBy(int $amount) : self
    {
    return new self(
    $this->amount() + $amount,
    $this->currency()
    );
    }
    }

    View Slide

  45. Entidades

    View Slide

  46. *Identidade

    View Slide

  47. UUID

    View Slide


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

    View Slide

  49. EVITAR
    INVALID
    STATE DA ENTIDADE

    View Slide

  50. INDEPENDE DE
    STORAGE

    View Slide

  51. #TIPS

    View Slide

  52. PERSISTÊNCIA
    ORM

    View Slide

  53. NÃO USE
    ANNOTATIONS

    View Slide

  54. Delivery
    Mechanism

    View Slide

  55. DDD
    É PRA MIM?

    View Slide

  56. Sylius

    View Slide

  57. PERGUNTAS?

    View Slide

  58. THANKS!
    @malukenho

    View Slide