Junior — Middle
Milline on Data Transfer Objecti roll rakenduse kihtide vahelise andmevahetuse protsessis?
sobes.tech AI
Vastus AI-lt
Data Transfer Object (DTO) is a simple object used for transferring data between layers of an application, for example, between the data access layer and the business logic layer or between the server and the client.
Role of DTO:
- Encapsulation of data without business logic.
- Simplification of data transfer, especially when working with remote calls or serialization.
- Reduction of dependency between layers, as DTO does not depend on the internal implementation of layers.
Example of DTO in PHP:
class UserDTO {
public string $name;
public string $email;
public function __construct(string $name, string $email) {
$this->name = $name;
$this->email = $email;
}
}
This object can be used to transfer user data between layers without transferring the entire model with business logic.