I have an Age Value Object which validates age betweens 2 const ( MinimumAge and MaximumAge )
At some point i want to be able to change this min and max range dynamically without editing code after project got published ( for example reading it from DB or fetching it from somewhere else... )
How can i do this without breaking DDD rules and be loyal to Value Object Self-Validating ?
I tried few ways but all broke DDD rules at some point
My suggestion is to not treat a value that can change as an invariant.
If you have different, but invariant, age ranges then you may have more than one
Agevalue object that is abstracted behind an interface and the object making use of the value object has some indicator of theAgeType. For example, you may have aRegistrationAgethat validates between ages 2-16 and another forVotingAgethat validates from 18-anything. However, if the ages may change then they really shouldn't be hard-coded as invariants in the value object. Instead, they may be provided to the value object as parameters that may be defined outside the domain (database, or some other settings, for instance).It may be that what you are after is more of a
Specification, or yourAgevalue object may act as a specification.