DDD: Retour d'expérience

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest. →

DDD: Retour d'expérience

Retour d'expérience sur ce que j'ai appris lors d'un projet perso fait en Symfony et en Domain

GBProd

May 12, 2016

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

33 slides
  1. /** * @ORM\Table(name="oc_advert") * @ORM\Entity(repositoryClass="OC\PlatformBundle\Repository\AdvertRepository") * @ORM\HasLifecycleCallbacks() */ class Advert

    { /** * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @ORM\Column(name="date", type="datetime") * @Assert\DateTime() */ private $date; /** * @ORM\Column(name="author", type="string", length=255) * @Assert\Length(min=2) */ private $author; /** * @ORM\Column(name="content", type="text") * @Assert\NotBlank() */ private $content; /** * @ORM\OneToOne(targetEntity="OC\PlatformBundle\Entity\Image", cascade={"persist", "remove"}) * @Assert\Valid() */ Code first
  2. Utiliser langage commun dans le modèle • Utiliser des constructeurs

    nommés • Tous les paramètres obligatoires sont dans le constructeur • Utiliser des méthodes plutôt que des setters • Rendre les classes du domaines finales • Utiliser des factories
  3. QuestionRepository final class Question { public static function ask( QuestionIdentifier

    $id, Author $author, $text, array $options, \DateTimeImmutable $endDate ) { } private function __construct(...) { }
  4. Avec doctrine ? • Utilisez le type embeddable pour les

    Object Value • Utilisez le YAML/XML au lieu des annotations (dans la couche infrastructure) • Attention aux jointures • Les id en Object Value, c’est possible
  5. Une spécification <?php namespace GBProd\ICantDecide\CoreDomain\Specification\Question; use GBProd\Specification\CompositeSpecification; class IsAvailable extends

    CompositeSpecification { public function isSatisfiedBy($candidate) { return $candidate->getEndDate() > new \DateTime('now'); } }
  6. Une spécification avec paramètres <?php namespace GBProd\ICantDecide\CoreDomain\Specification\Question; use GBProd\Specification\CompositeSpecification; class

    HasMoreVoteThan extends CompositeSpecification { public function __construct($minVote) { $this->minVotes = $minVotes; } public function isSatisfiedBy($candidate) { [...]
  7. Composition <?php $manyVotes = new HasMoreVoteThan(1000); $available = new IsAvailable();

    $byMe = new IsAskedBy(‘gbprod’); $isPopular = $available ->andX($manyVotes) ->andX($byMe->not()) ; $isPopular>isSatifiedBy($question);

More Decks by GBProd

Other Decks in Technology