I'm looking into developing my entities so that they cannot be in an invalid state.
In particular I'm starting with my Customer entity. This would have fields like:
- Title (enum)
- FirstName (string)
- LastName (string)
- Address (value object with another 6 fields)
- MainTelephone (string)
- AlternateTelephone (string)
- EmailAddress (string)
I've added methods such as ChangeOfAddress() to facilitate the changing of address, which will ensure a valid address is entered as a replacement.
In the UI, I consider most fields (except for AlternateTelephone and EmailAddress) as 'required', encouraging users to complete fields such as Title to make addressing mail shots easier in the future.
For methods like ChangeOfAddress() the concept of 'invalid state' is an easy one, as I can apply validation on the new Address value object, but for the construction of a new Customer object I'm not as sure.
I guess my question is, should the bare minimum for the construction of a Customer entity include all the fields I feel are 'required' from the perspective of the UI? I can't imagine how creating a Customer with only a FirstName and LastName (without any contact details), would be valid in the business sense I intend to use the Customer object in. Although in a sense FirstName and LastName are good starting points for a minimum description of a Customer and I guess the Customer wouldn't be 'invalid' it'd just be lacking enough information to be useful to my business needs (which would be, to be able to contact them).
Hope this makes sense, I'd be interested to hear any opinions, as I'm still learning as I go.