Hello. Thanks for great gems set for better architecture.
I have a common question about best practices for Domain entities and value objects.
The main question: should I include validation rules to the object itself. Consider the easy Address value object:
class Address < Dry::Types::Struct include Dry::Types.module attribute :address_line1, Strict::String attribute :address_line2, Strict::String attribute :city, Strict::String attribute :state, Strict::String attribute :zip, Strict::String end
Despite it uses strict string type, it allows blank string: ‘’.
Should I add presence validation to object attributes, or validation user input with
dry-validations schema is enough.
It seems that obvious answer is: yes, I should.
But I afraid to repeat myself, because I definitely should validate user input with
dry-validation schema, and it seems, I can’t use the same schema in object. So, I’ll have validation rules duplication between object attributes and user input schema.
How do you resolve this problem?