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 full-size slide

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

    View full-size slide

  3. How it started

    View full-size slide

  4. Let's code...

    View full-size slide

  5. Let's try to code...

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  10. Ubiquitous language

    View full-size slide

  11. Write a glossary

    View full-size slide

  12. 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 full-size slide

  13. Anemic model vs Rich domain model

    View full-size slide

  14. Does Symfony love DDD?
    Doctrine ORM

    Messenger

    Workflow

    App structure

    Validator

    Forms
    !

    View full-size slide

  15. Tac$cal pa$erns

    View full-size slide

  16. “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 full-size slide

  17. 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 full-size slide

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

    View full-size slide