Luciano Queiroz
Backend Engineer @ HelloFresh
6º meetup da comunidade PHP Pernambuco
Senior PHP Software Engineer @ LPCDev
Backend Engineer @ Hello Fresh
Brasil????
O que é DDD?
Problem Space
Solution Space
Vaughn Vernon - Domain-Driven Design Distilled
Vaughn Vernon - Implementing Domain-Driven Design
Navigation
Destination
Origin
Route
Navigation
Destination
Origin
Route
Driver
Car
Plate
Navigation
Destination
Origin
Route
Driver
Car
Plate
Alert
Collaborator
Location
Score
Navigation
Destination
Origin
Route
Alert
Collaborator
Location
Score
Driver
Car
Plate
RideAvailability
Commutation
Rider
Commutation
Commutation
Navigation
Destination
Origin
Route
Alert
Collaborator
Location
Score
Driver
Car
Plate
RideAvailability
Commutation
Rider
Commutation
Commutation
Rental
CarRentAvailability
Car
Duration
Total
Price
Renter
Commutation
Rental
NavigationContext
RentalContext
CollaborationContext
CarPoolContext
Navigation
Routes
Destination
Origin
ETA
ETA
Commutation
Car
Rental
Price
Duration
Renter
CarOwner
SeatsAvailable
CarCapacity
Rider
Driver
Driver
Collaborator
Editor
Alert
Location
Car
NavigationContext
RentalContext
CollaborationContext
CarPoolContext
Navigation
Routes
Destination
Origin
ETA
ETA
Commutation
Car
Rental
Price
Duration
Renter
CarOwner
SeatsAvailable
CarCapacity
Rider
Driver
Driver
Collaborator
Editor
Alert
Location
Car
NavigationContext
RentalContext
CollaborationContext
CarPoolContext
Navigation
Routes
Destination
Origin
ETA
ETA
Commutation
Car
Rental
Price
Duration
Renter
CarOwner
SeatsAvailable
CarCapacity
Rider
Driver
Driver
Collaborator
Editor
Alert
Location
Car
NavigationContext
RentalContext
CollaborationContext
CarPoolContext
Navigation
Routes
Destination
Origin
ETA
ETA
Commutation
Car
Rental
Price
Duration
Renter
CarOwner
SeatsAvailable
CarCapacity
Rider
Driver
Driver
Collaborator
Editor
Alert
Location
Car
NavigationContext
RentalContext
CollaborationContext
CarPoolContext
Navigation
Routes
Destination
Origin
ETA
ETA
Commutation
Car
Rental
Price
Duration
Renter
CarOwner
SeatsAvailable
CarCapacity
Rider
Driver
Driver
Collaborator
Editor
Alert
Location
Car
Driver
Car (n)
Profile
Plate
<?php
declare(strict_types=1);
namespace RecipeApi\Domain;
use Prooph\EventSourcing\AggregateRoot;
class Driver extends AggregateRoot
{
private $driverId;
private $cars = [];
private $email;
public static function new(
DriverId $driverId,
Email $email
) : self {
$self = new self();
$self->recordThat(DriverWasRegistered::fromRequestData($recipeId, $email));
return $self;
}
public function aggregateId(): RecipeId
{
return $this->driverId;
}
public function cars(): array
{
return $this->cars;
}
public function whenDriverWasRegistered(DriverWasRegistered $event)
{
$this->driverId = DriverId::fromString($event->aggregateId());
$this->email = $event->email();
}
public function addCar(Car $car)
{
$this->recordThat(CarWasAdded::fromRequestData($this->driverId, $car));
}
public function whenCarWasAdded(CarWasAdded $event)
{
$this->cars[] = $event->car();
}
}
<?php
use Rhumsaa\Uuid\Uuid;
final class DriverId
{
private $uuid;
private function __construct(Uuid $uuid)
{
$this->uuid = $uuid;
}
public static function new(): self
{
return new self(Uuid::uuid4());
}
public static function fromString(string $uuid): self
{
return new self(Uuid::fromString($uuid));
}
public function __toString(): string
{
return (string) $this->uuid;
}
public function uuid(): Uuid
{
return $this->uuid;
}
}
DriverWasCreated
2 CarWasAdded
1 CarWasRemoved
DriverWasCreated
1 CarWasAdded
By Luciano Queiroz
Slides para apresentação do 6º Meetup PHP Pernambuco.
Backend Engineer @ HelloFresh