哪个课堂设计更好?
哪个课程设计更好,为什么?
public class User
{
public String UserName;
public String Password;
public String FirstName;
public String LastName;
}
public class Employee : User
{
public String EmployeeId;
public String EmployeeCode;
public String DepartmentId;
}
public class Member : User
{
public String MemberId;
public String JoinDate;
public String ExpiryDate;
}
要么
public class User
{
public String UserId;
public String UserName;
public String Password;
public String FirstName;
public String LastName;
}
public class Employee
{
public User UserInfo;
public String EmployeeId;
public String EmployeeCode;
public String DepartmentId;
}
public class Member
{
public User UserInfo;
public String MemberId;
public String JoinDate;
public String ExpiryDate;
}
这个问题只是通过认识到继承模型是“IS-A”关系来回答的,而成员模型则是“HAS-A”关系模型。
哪一个是正确的? 这是你的答案。
我不喜欢任何一个。 当某人既是会员又是员工时会发生什么?
问问自己以下几点:
通常,在代码复杂性和所需效率的限制下,努力模拟您的程序模拟的实际情况。
链接地址: http://www.djcxy.com/p/53937.html