I have a base Address
class which defines basic address properties and acts as an CRUD object:
- Name
- Company
- Address Line 1
- Address Line 2
- Address Line 3
- City
- State
- Postal Code
- Country
I have a 'ShipToAddress' class which extends Address and includes two more properties:
- Phone Number
- Email Address
Address
includes validation methods for each of its properties, and ShipToAddress
includes validation for only its properties (Phone Number and Email Address).
My issue is, I also want to account for both USA and International addresses for both of these classes without duplicating code, so that I can have different validation methods for State and Postal Code. USA State validation would ensure that the value is one of the 50 States. International validation would simply ensure that it does not exceed the length allowed in the database.
How can I design this to allow for any number of different types of addresses (USA, Canada, etc.) but also have the base Address
class and the ShipToAddress
class, without duplicating the code? I basically want the following:
Address
Base ClassShipToAddress
USAAddress
USAShipToAddress
***Address
***ShipToAddress