Data Transfert Object (DTO)

source

A data transfer object is an object that carries data between processes/objects.

The difference between data transfer objects and business objects or data access objects is that a DTO does not have any behavior. In other words, DTOs are simple objects that should not contain any business logic but may contain serialization and deserialization mechanisms for transferring data.

They are a composition of scalar, other DTOs and value objects. They are immutable. They are not supposed to be persisted, however they are serializable.


final class fooDto
{
    public function __construct(
        private int $propertyA, 
        private string $propertyB
    ) {
    }

    public function getPropertyA(): int
    {
        return $this->propertyA;
    }

    public function getPropertyB(): string
    {
        return $this->propertyB;
    }
}