I have a class structure that looks like this:
class Person
{
public virtual string FirstName {get;set;}
public virtual string LastName {get;set;}
public virtual Address HomeAddress {get;set;}
}
class Address
{
public virtual string Street {get;set;}
public virtual string City {get;set;}
public virtual string State {get;set;}
public virtual string ZipCode {get;set;}
public virtual string Country {get;set;}
}
Then I have the idea of a person with Required Address and a person that uses the RequiredAddress... so I have my new "Required" address looking like:
class RequiredAddress
: Address
{
[Required]
public override string Street {...}
[Required]
public override string City {...}
[Required]
public override string State {...}
[Required]
public override string ZipCode {...}
[Required]
public override string Country {...}
}
but when I just newed up an instance of RequiredAddress into the Address field of my RequiredPerson address, MVC couldn't seem to detect the [Required] tags, and I wound up having to do this:
class PersonRequiredAddress
: Person
{
public new RequiredAddress Address {get;set;}
}
Now, because we had to do this, we wound up having to re-do our DAL to handle the differences in objects... which feels like a miserable code smell to me. Can anyone provide a better solution to this quandary we face?