Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I reuse Value Objects?

According to Domain-Driven Design, can I import and reuse common Value Objects like Email, SocialSecurityNumber, Currency, etc. from external sources?

It seems it would be bad because I'm relying on external code in the heart of my Domain, but for the other side, it seems I would be reinventing the wheel by rewritten the same code over and over again.

like image 382
Alan Willms Avatar asked Apr 07 '26 15:04

Alan Willms


1 Answers

Well... generic stuff like Email, SSN can be imported and reused. Basically, the problem with imported stuff is that they might mean something else in their original bounded context. For example, Currency might not be what you need for your Domain. But things like email are generic enough not to matter.

tldr; It's ok to reuse generic concepts as long as they are generic enough that they mean the same thing in your Domain.

P.S: You can reuse them even more in validating input i.e outside the domain.

like image 70
MikeSW Avatar answered Apr 11 '26 08:04

MikeSW



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!