【发布时间】:2012-03-15 02:55:33
【问题描述】:
我有两个抽象类 Business 和 Person。问题是我的客户类型可以是企业或个人。有没有办法对此进行建模,以便我没有 CustomerBusiness 和 CustomerPerson 类?多重继承不是一个选项,因为这是 C#。看了这么久,只见树木不见森林。
public abstract class Business {
public string Name { get; set; }
}
public abstract class Person {
public string FirstName { get; set; }
public string LastName { get; set; }
public string MiddleName { get; set; }
public DateTime? BirthDate { get; set; }
public string Comments { get; set; }
}
public class CustomerBusiness : Business, CustomerRoles {
public bool BillTo { get; set; }
public bool ShipTo { get; set; }
public bool DeliverTo { get; set; }
public EntityType Type { get; set; }
}
public class CustomerPerson : Person, CustomerRoles {
public bool BillTo { get; set; }
public bool ShipTo { get; set; }
public bool DeliverTo { get; set; }
public EntityType Type { get; set; }
}
public interface CustomerRoles {
bool BillTo { get; set; }
bool ShipTo { get; set; }
bool DeliverTo { get; set; }
}
【问题讨论】:
标签: c# c#-4.0 inheritance interface base-class