I recently asked this question: https://stackoverflow.com/questions/48582699/equality-for-a-dateofbirth-value-object. I am going to avoid a DateOfBirth value object. Instead I am planning to use a type alias. I have a few options with regards to my constructor:
Option 1
using DateOfBirth=System.DateTime; DateOfBirth DateOfBirth; public Person (DateOfBirth dateOfBirth) { if (dateOfBirth.TimeOfDay.TotalSeconds > 0) throw new ArgumentException("Date of birth cannot contain a time.") DateOfBirth = dateOfBirth; } Option 2
DateOfBirth DateOfBirth; public Person(int day, int month, int year) { //Validation to make sure day, month and year are valid. DateOfBirth = new DateOfBirth(year,month,day); } I am trying to decides, which option to choose. The validation for option two could be quite complex because some months have different number of days. Therefore I am hoping that option one is suitable for this.
Also, should I be using type aliases in my Unit Tests or just refer to them as the primitive type i.e. date time?