Sorry in advance if this question is so trivial.
The situation
There is a Customer entity whose ID is limited to two letters (A to Z) in the database.
Also, a user can enter the ID value from a Windows form. I think that the best option is that this form will validate (using the controller) with a regular expression like this ^[a-zA-Z0-9]{2}$ whether the value is valid.
The question(s)
- Does the
Customerentity should also do the validation when I set the value of the ID property? - Should this validation be outsourced if, for example, there is also similar validation in other properties of the entity?
I think that the answer is that it depends if the property value is a requirement of the user or it is a design decision on the database, but I appreciate your knowledge and experience to guide me on the correct way.
Thanks in advance.
IDcolumn on the database is defined asCHAR(2), so a database error will be thrown when theIDvalue exceeds the maximum length. This and the "only-letter" restriction is set also by the final user on his specs. Then, if I don't validate value length before introducing it into the database, there is a problem. – HuorSwords Jun 17 '14 at 14:21Customerobject from XML file. The validation of the serialization will remain onCustomerobject itself or outside of the object (assumming SRP)? – HuorSwords Jun 17 '14 at 14:31