I need to over override a property from a List class. My class for example is setup as follows:
public class Customer
{
private int _ID;
private string _CustomerName;
private List<CustomerAddress> _CustomerAddressList;
public int ID { get { return _ID; } set { _ID = value; } }
public string CustomerName
{
get { return _CustomerName; }
set { _CustomerName = value; }
}
public List<CustomerAddress> CustomerAddressList
{
get { return _CustomerAddressList; }
set { _CustomerAddressList = value; }
}
}
public class CustomerAddress
{
private string _Address1;
private string _TelephoneNumber;
public string Address1
{
get { return _Address1; }
set { _Address1 = value; }
}
public virtual string TelephoneNumber
{
get { return _TelephoneNumber; }
set { _TelephoneNumber = value; }
}
}
Now I have my Business Layer class which inherits the customer class.
I can override the properities of the customer class, but i can’t work out how to override the properties of the CustomerAddress class in my CustomerBL class? I don’t want to override the List setting but to override the individual properties on each item in the list.
According to the original design, there are only awful solutions:
If the entity instances are inherited, we have this:
If we inherit the BL classes, we have this:
If we use Generics, we have this
The problem, no doubt, is that there are two different inheritance chains:
And it’s not possible to have a good decision on which is the rigth waty to do it (in fact, I think, with this design there’s no way of doing it right).
It’s much better to have entities and BL classes independent of each other, so that you can keep both inheritance chains independent, and decide what can and should be inherited in its chain.
Entities can inherit for each other. All right, typical case:
Inheriting BL Classes (dont’ like it):
“BL classes using other BL classes” (that’s the way I like it):
In fact, it would be better to have an AddressBl that can be used by both WorkerBl2 and PersonBl2