Understanding and implementing Value Objects
HTML-код
- Опубликовано: 3 авг 2024
- 👨💻 Learn Test-Driven Development with Laravel!
tddwithlaravel.com
Sign up to 30 Days of Laravel 👉🏻 30daysoflaravel.com
👨💻 Sign up to my newsletter and receive PHP, JS and Laravel news in a weekly-basis:
subscribe.mateusguimaraes.com
🎉 Party up:
/ mateusjatenee
/ mateusjatenee
/ mateusguimaraes
Thanks for watching! Наука
This should be one of the top 100 viewed videos regarding Laravel on RUclips.
Thank you so much Ryan!
vc é brabo demais!!
Are value objects an evolution of DTOs?
Kinda. DTO just cares about the shape of the data. In this case, temperature is an integer so thats it. It doesnt validate and it doesnt care about the business. It just force you to have the data in the format that you need (array, string, integer and so on). Once you need to have valid data in the domain perspective, like temperature cant be below -20 you have a value object.
Not an evolution but just different use cases.
Is the value object also responsible to convert the temperature from one unit to another?
for example:
$temperature = new temperature(100, 'celsius');
$temperature->getFahrenheit(); // 212
or
$temperature = Temperature::fromCelsius(100);
for me, yes !
It’s common to have formatting inside a VO. Just try not to go overboard with it :-)
What font are you used for your phpstorm?
Operator Mono
Instructions unclear.
$request->validate(['temp' => ['min:-20', 'max:60']]);
Problem solved.
That works from the http request perspective but sometimes you will find yourself reading data from a CSV uploaded by the user or from a command line. Value objects can be useful in such situations.
Big brain energy