我有两个抽象类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; }
}
谢谢埃德,我开始看到你的观点。我需要澄清的是,我认为我需要保持业务和人员类的抽象,因为将有其他类将始终具有业务和人员属性集。例如:供应商,部门,部门等... – Chris 2012-02-27 15:27:48
我不确定我能否使用这个方法,因为在这个项目中有其他限制(不是我原来的问题),但这个解决方案是最好的答案到目前为止已经找到了。谢谢,埃德。 – Chris 2012-02-28 13:04:57