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

A love story starring Symfony and Domain-Driven Design

A love story starring Symfony and Domain-Driven Design

This is the story of how I discovered Domain-Driven Design, what happened when I tried to apply it to a Symfony framework project, and what are the key takeaways.

Talk given at SymfonyCon Amsterdam 2019, unconference

Romaric Drigon

November 22, 2019
Tweet

More Decks by Romaric Drigon

Other Decks in Programming

Transcript

  1. A love story
    starring Symfony
    and Domain-Driven Design
    Romaric Drigon @ SymfonyCon Amsterdam, 22/11/2019

    View Slide

  2. @romaricdrigon
    So,ware engineer @ ASIT VD
    !

    View Slide

  3. How it started

    View Slide

  4. View Slide

  5. Let's code...

    View Slide

  6. Let's try to code...

    View Slide

  7. What went wrong?
    2 pre-requisite for DDD:
    • an itera)ve process is in place
    • domain experts are available and coopera)ve

    View Slide

  8. Hard fact #1: Most us can't do DDD

    View Slide

  9. Hard fact #2: Most us don't need DDD

    View Slide

  10. S"ll, we can learn a lot from DDD

    View Slide

  11. Ubiquitous language

    View Slide

  12. Write a glossary

    View Slide

  13. Automa'c glossary
    $metadatas = $this->doctrine->getMetadataFactory()->getAllMetadata();
    foreach ($metadatas as $metadata) {
    $fields = [];
    foreach ($metadata->getFieldNames() as $fieldName) {
    $property = $metadata->getReflectionClass()->hasProperty($fieldName) ? $metadata->getReflectionClass()->getProperty($fieldName) : null;
    $fields[$fieldName] = [
    'doc' => $property ? $this->cleanPhpDoc($property->getDocComment()) : null,
    'isIdentifier' => $metadata->isIdentifier($fieldName),
    'name' => $fieldName,
    'isNullable' => $metadata->isNullable($fieldName),
    'type' => $metadata->getTypeOfField($fieldName),
    ];
    }
    $entities[] = [
    'doc' => $this->cleanPhpDoc($metadata->getReflectionClass()->getDocComment()),
    'name' => $metadata->getReflectionClass()->getShortName(),
    'properties' => $fields,
    ];
    }
    $doc = $this->twig->render('doc.html.twig', ['entities' => $entities]);

    View Slide

  14. Anemic model vs Rich domain model

    View Slide

  15. Does Symfony love DDD?
    Doctrine ORM

    Messenger

    Workflow

    App structure

    Validator

    Forms
    !

    View Slide

  16. Tac$cal pa$erns

    View Slide

  17. View Slide

  18. “A pa&ern is not a cookbook.
    It lets you start from a base of experience to
    develop your solu;on, and it gives you some
    language to talk about what you are doing.”
    — Eric Evans, Domain-Driven Design

    View Slide

  19. Final word
    Read books!
    You can improve a lot quality of your so4ware by improving
    processes and communica9on around
    Do not be a DDD groupie

    View Slide

  20. Thank you for your a,en.on
    h"ps:/
    /romaricdrigon.github.io/

    View Slide