Lets say I have a Phone number my classes need to validate and keep track of and for the most part a phone number is just a string so in an attempt to be DRY one would just create a Phone class and inherit from string. Since I can’t do that what is the next best approach? Adding a string as a private member and overloading the equal/= operators so it can be passed and set as a string?
Share
May I suggest that you take Johannes Rudolph’s or C. Ross’s advice. You can also review the behaviour of the implicit keyword which will let you assign in a String-like manner while still doing validation.
i.e.: