jorge07 / symfony-6-es-cqrs-boilerplate

Symfony 6 DDD ES CQRS backend boilerplate.
MIT License
1.07k stars 187 forks source link

Question about value objects #107

Closed ferrius closed 5 years ago

ferrius commented 5 years ago

IMHO value objects should carry more complex business logic than validation rules. Wrapping every scalar value in own class complicates simple things. The best way i think to use private setters with assertions inside.

jorge07 commented 5 years ago

By doing this your aggregates will grow a lot. And your aggregate will need to deal with logic than can be encapsulated in a better way. It will also simplify your tests suite and allow you to reuse and also cast this object in another places.

Here for example: https://github.com/jorge07/symfony-4-es-cqrs-boilerplate/blob/master/src/Domain/User/Specification/UniqueEmailSpecificationInterface.php#L15

It will ensure you receive a valid email and not just an string. By doing this you guarantee consistency and symplify test suite.

ferrius commented 5 years ago

I understand, thank you

jorge07 commented 5 years ago

You're very welcome