示例#1
0
        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();
        }
示例#2
0
 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));
     }
 }
示例#3
0
 /// <summary>
 /// Accept method
 /// </summary>
 /// <param name="visitor"></param>
 /// <returns></returns>
 public override int GetSalary(SalaryVisitor visitor)
 {
     return(visitor.VisitSalary(this));
 }
示例#4
0
 /// <summary>
 /// Accept method
 /// </summary>
 /// <param name="visitor"></param>
 /// <returns></returns>
 public virtual int GetSalary(SalaryVisitor visitor)
 {
     return(visitor.VisitSalary(this));
 }