DTOs vs Value Objects
DTOs
- used for transferring data between layers of an application, such as between controllers and services, or between the application and external systems (e.g., API requests and responses).
- it replaces array (key are not predefined) with more structured objects (properties)
- good use case: Laravel HTTP Client returns data as array -> convert to DTO
Value Object
-
focuses on representing a specific value or concept and often contains behavior related to that value
-
typically immutable; new value -> new instance
- examples: address, money, temperature, map coordinates