Hi there
I have abstract class called Tenant and Customer. The tenant in this case is like owner of the application for multi tenant application model.
The relationship between these 2 class are Many to One relationship.
public abstract class Tenant
{
protected Int32 id;
protected String name;
public Int32 ID { get; set; }
public String Name { get; set; }
public abstract bool Add();
public abstract bool Update();
public abstract bool Delete();
public abstract List<Tenant> Get();
}
public class ApplicationTenant: Tenant
{
public ApplicationTenant() { }
public override Int32 ID
{
get { return id; }
set { id = value; }
}
public override String Name
{
get { return name; }
set { name= value; }
}
public override List<Tenant> Get()
{
...
}
}
public abstract class Customer
{
protected Int32 id;
protected String name;
protected Tenant tenant;
public Int32 ID { get; set; }
public String Name { get; set; }
public Tenant Tenant { get; set; }
public abstract bool Add();
public abstract bool Update();
public abstract bool Delete();
public abstract List<Customer> Get();
}
public class CorporateCustomer : Customer
{
public CorporateCustomer () { }
public override Int64 ID
{
get { return id; }
set { id = value; }
}
public override String Name
{
get { return name; }
set { name= value; }
}
public override Tenant Tenant
{
get { return tenant; }
set { tenant= value; }
}
public override List<Customer> Get()
{
...
}
...
}
With the OO design above, we know that method of List<Tenant> Get()
needs to be overrided.
BUT the issue are:
1) The return value of the Get() in the CorporateCustomer is always going to be List<CorporateCustomer>.
It meeans that I have to override List<Tenant> Get()
without being implementation and create another following method
public List<CorporateCustomer > Get()
{
return ???;
}
2) If I override anyway for this method above and on the retun I just cast it ... it won't work anyway. ?!!? Casn casting to List<CorporateCustomer>
from List<Customer>
3) The property below:
public override Tenant Tenant
{
get { return tenant; }
set { tenant= value; }
}
means again I have to override this BUTI don't I really used this cause the CorporateCustomer is always going to be used the ApplicationTenant instead as return NOT Tenant.
public CorporateTenant Tenant
{
get { return corprateTenant; }
set { corprateTenant= value; }
}
So is this the right design? Cause it's kinda waste of the abstraction.
Some people suggests to use Generic abstract class instead which I am not sure it's going to help anyway.
I am appreciated your feedback.
Thanks