B
B
BonBon Slick2018-05-21 20:14:48
Software design
BonBon Slick, 2018-05-21 20:14:48

If there is a DTO for each entity, then which application layer is responsible for validation?

Let's say there is an entity User, it has 2 fields, email and password. It's 2 ValueObjects. VOs must always be valid, before we create them we use DTOs. And the question arose, Which of the 2 levels, DTO or VO, are responsible for validation?

$dto = new UserDTO($data) // тут валидируем
$user = new User($dto);

....
 
public function __construct(UserDTO $dto)
{
   $this->email = new UserVOEmail($dto->email); //  или тут валидируем
...
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dmitriy, 2018-05-21
@BonBonSlick

Value object is not just a class structure but has the logic of work within its entity, validation is suitable.
DTO - purely structure for data transport

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question