Beispiel #1
0
        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);
        }
        private static void EmployeesDemo()
        {
            var ivan = new Clerk { Name = "Ivan", Income = 20000, VacationDays = 8 };
            var peter = new Clerk { Name = "Peter", Income = 25000, VacationDays = 14 };
            var george = new Director { Name = "George", Income = 35000, VacationDays = 16 };
            var bob = new President { Name = "Bob", Income = 45000, VacationDays = 21 };

            // Setup employee collection
            var employees = new EmployeesList();
            employees.Attach(ivan);
            employees.Attach(peter);
            employees.Attach(george);
            employees.Attach(bob);

            // Employees are 'visited'
            employees.Accept(new IncomeVisitor());
            employees.Accept(new VacationVisitor());
            bob.Accept(new IncomeVisitor());

            // We can create and apply new visitors (e.g. work from home days)
            // as well as new employee successors

            // We can create SumIncomeVisitor to collect information for us
        }