public void RemoveComponentEmployee(EmployeeBySelf component) { if (Employees != null && Employees.Any() && component != null) { Employees.Remove(component); } }
public void AddComponentEmployee(EmployeeBySelf component) { if (Employees == null) { Employees = new List <EmployeeBySelf>(); } Employees.Add(component); }
public static void Test() { Console.WriteLine(); Console.WriteLine(); Console.WriteLine("组合模式-安全方式"); Console.WriteLine(); var boss = new ManagerBySelf("老板", "唱怒放的生命"); var HR = new EmployeeBySelf("人力资源", "聊微信"); var PM = new ManagerBySelf("项目经理", "不知道干啥"); var CFO = new ManagerBySelf("财务主管", "看剧"); var CTO = new ManagerBySelf("技术主管", "划水"); var UI = new EmployeeBySelf("设计师", "画画"); var operater = new EmployeeBySelf("运营人员", "兼职客服"); var webProgrammer = new EmployeeBySelf("程序员", "学习设计模式"); var backgroundProgrammer = new EmployeeBySelf("后台程序员", "CRUD"); var accountant = new EmployeeBySelf("会计", "背九九乘法表"); var clerk = new EmployeeBySelf("文员", "给老板递麦克风"); boss.AddComponentEmployee(HR); boss.AddComponentManager(PM); boss.AddComponentManager(CFO); PM.AddComponentEmployee(UI); PM.AddComponentManager(CTO); PM.AddComponentEmployee(operater); CTO.AddComponentEmployee(webProgrammer); CTO.AddComponentEmployee(backgroundProgrammer); CFO.AddComponentEmployee(accountant); CFO.AddComponentEmployee(clerk); boss.CheckWork(); }