To use the structure that you use, you will need several inheritances for the one who is an accountant and a programmer, in addition to the fact that new roles can be added to the system, and this does not exist in C #. You should consider a different design. One of the possibilities:
public class Employee { ... IList<Role> Roles; bool isActive; public void TerminateRole(Role role) { Roles.Remove(role); if(Roles.Count == 0) { isActive = false; } } } public class Role { abstract string Name { get;} } public class ProgrammerRole : Role { override string Name { get { return "Programmer"; } } }
You can then subclass Role for each type, and you can decide to close only one role or all of them.
source share