static void Main(string[] args) { EmployeeList list = new EmployeeList(); Employee fte1, fte2, fte3, pte1, pte2; fte1 = new FulltimeEmployee("张无忌", 3200, 45); fte2 = new FulltimeEmployee("杨过", 2000, 40); fte3 = new FulltimeEmployee("段誉", 2400, 38); pte1 = new ParttimeEmployee("洪七公", 80, 20); pte2 = new ParttimeEmployee("郭靖", 60, 18); list.addEmployee(fte1); list.addEmployee(fte2); list.addEmployee(fte3); list.addEmployee(pte1); list.addEmployee(pte2); Console.WriteLine("财务部 访问数据!"); Department fadep = new FADepartment(); list.accept(fadep); Console.WriteLine(); Console.WriteLine("人力资源部 访问数据!"); Department hrdep = new HRDepartment(); list.accept(hrdep); Console.ReadLine(); }
static void Main2302() { Console.WriteLine("Hello Visitor Pattern!"); EmployeeList empList = new EmployeeList(); IEmployee fteA = new FullTimeEmployee("0001", 3200.00, 45); IEmployee fteB = new FullTimeEmployee("0002", 2000, 40); IEmployee fteC = new FullTimeEmployee("0003", 2400, 38); IEmployee fteD = new PartTimeEmployee("0004", 80 * 40, 20); IEmployee fteE = new PartTimeEmployee("0005", 60 * 40, 18); empList.AddEmployee(fteA); empList.AddEmployee(fteB); empList.AddEmployee(fteC); empList.AddEmployee(fteD); empList.AddEmployee(fteE); var hr = new HRDepartment(); empList.Action(hr); Console.WriteLine("****************************************************"); var finance = new FinanceDepartment(); empList.Action(finance); Console.ReadLine(); }
static void Main(string[] args) { EmployeeList empList = new EmployeeList(); IEmployee fteA = new FullTimeEmployee("梁思成", 3200.00, 45); IEmployee fteB = new FullTimeEmployee("徐志摩", 2000, 40); IEmployee fteC = new FullTimeEmployee("梁徽因", 2400, 38); IEmployee fteD = new PartTimeEmployee("方鸿渐", 80, 20); IEmployee fteE = new PartTimeEmployee("唐宛如", 60, 18); empList.AddEmployee(fteA); empList.AddEmployee(fteB); empList.AddEmployee(fteC); empList.AddEmployee(fteD); empList.AddEmployee(fteE); Department dept = new HRDepartment(); if (dept != null) { empList.Accept(dept); } Console.ReadKey(); }