我有以下域名。
角色是一个抽象类。程序员扩展角色。员工有多个角色,如程序员、经理等。
我想为它创建一个模型。我们如何composition
在员工实体中指定角色?
注意:我不能在 Roles 表中添加 EmpID。因为相同的角色将适用于许多员工。
当前型号
所需概念模型的伪代码
public abstract class Role
{
public abstract string RoleName { get; }
public abstract int RoleID { get; }
}
public class ProgrammerRole : Role
{
public override string RoleName { get { return "Programmer"; } }
public override int RoleID { get { return 101; } }
}
public class ManagerRole : Role
{
public override string RoleName { get { return "Manager"; } }
public override int RoleID { get { return 102; } }
}
public class Employee
{
private IList<Role> roles;
public IList<Role> RolesList
{
get
{
return roles;
}
}
public int EmployeeID { get; set; }
//Constructor
public Employee()
{
roles = new List<Role>();
}
public void TerminateEmployeeByRole(Role role)
{
if (RolesList == null)
{
//If employee has no role, make as inactive
isActiveEmployee = false;
}
else
{
//If employee has no role other than the input role, make as inactive
RolesList.Remove(role);
if (RolesList.Count == 0)
{
isActiveEmployee = false;
}
}
}
}