static void Main(string[] args) { // Setup structure ElementStructure structure = new ElementStructure(); structure.Attach(new Employee { Name = "Risto Reipas", Salary = 3000, VacationDays = 20 }); structure.Attach(new Employee { Name = "Erno Perälä", Salary = 3200, VacationDays = 40 }); structure.Attach(new Employee { Name = "Sauli Niinistö", Salary = 13000, VacationDays = 2 }); // Create visitor objects IVisitor salaryFairy = new SalaryVisitor(); IVisitor vacationFairy = new VacationVisitor(); // Structure accepting visitors structure.Accept(salaryFairy); structure.Accept(vacationFairy); // Wait for user Console.ReadLine(); }
private void btCompute_Click(object sender, System.EventArgs e) { VacationVisitor vac = new VacationVisitor(); bVacationVisitor bvac = new bVacationVisitor(); for (int i = 0; i < empls.Length; i++) { empls[i].accept(vac); //get the employee empls[i].accept(bvac); } lsVac.Items.Add("Total vacation days=" + vac.getTotalDays().ToString()); lsVac.Items.Add("Total boss vacation days=" + bvac.getTotalDays().ToString()); }
static void Main(string[] args) { //Object structure Employees employees = new Employees(); //Elements Element clerk = new Clerk("Edward", 500, 6); Element director = new Director("Jonathan", 600, 8); //Visitors IVisitor incomeVisitor = new IncomeVisitor(); IVisitor vacationVisitor = new VacationVisitor(); // Attach elements to the object structure employees.Attach(clerk); employees.Attach(director); //Perform operation of different visitors. employees.Accept(incomeVisitor); employees.Accept(vacationVisitor); }
static void Main(string[] args) { var employees = new Employees(); var director = new Director { Name = "Steve", Income = 100000, VacationDays = 100 } as Employee; var president = new President { Name = "Bob", Income = 1000000, VacationDays = 10 } as Employee; var clerk = new Clerk { Name = "Mary", Income = 10000, VacationDays = 1 } as Employee; employees.EmployeesList.AddRange(new [] { director, president, clerk }); var incomeVisitor = new IncomeVisitor(); var vacationDaysVisitor = new VacationVisitor(); employees.Accept(incomeVisitor); employees.Accept(vacationDaysVisitor); }
static void Main(string[] args) { Employee xz = new Engineer("小张", "工业设计部", 3000.0, 10); Employee xw = new Engineer("小王", "工业设计部", 3100.0, 11); Employee xc = new Engineer("小张", "营销零售部", 2800.0, 5); Employee xl = new Engineer("小李", "营销零售部", 2900.0, 4); Employee xzh = new Engineer("小周", "财务管理部", 3200.0, 3); Employees employees = new Employees(); employees.Attach(xz); employees.Attach(xw); employees.Attach(xc); employees.Attach(xl); employees.Attach(xzh); Visitor incomeVisitor = new IncomeVisitor(); Visitor vacationVisitor = new VacationVisitor(); employees.Accept(incomeVisitor); employees.Accept(vacationVisitor); Console.ReadKey(); }