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(); }
static void ProcessSalaries(IEnumerable <Employee> employees, SalaryVisitor salaryCalculator) { Console.WriteLine("{0,-12}{1,7}", "Employee", "Salary"); foreach (var employee in employees) { Console.WriteLine("{0,-12}{1,7}", employee.Name, employee.GetSalary(salaryCalculator)); } }
/// <summary> /// Accept method /// </summary> /// <param name="visitor"></param> /// <returns></returns> public override int GetSalary(SalaryVisitor visitor) { return(visitor.VisitSalary(this)); }
/// <summary> /// Accept method /// </summary> /// <param name="visitor"></param> /// <returns></returns> public virtual int GetSalary(SalaryVisitor visitor) { return(visitor.VisitSalary(this)); }