Esempio n. 1
0
        private static void Main(string[] args)
        {
            var person = new Person();

            person.Assets.Add(new BankAccount {
                Amount = 1000, MonthlyInterest = 0.01
            });
            person.Assets.Add(new BankAccount {
                Amount = 2000, MonthlyInterest = 0.02
            });
            person.Assets.Add(new RealEstate {
                EstimatedValue = 79000, MonthlyRent = 500
            });
            person.Assets.Add(new Loan {
                Owed = 40000, MonthlyPayment = 40
            });

            var netWorthVisitor = new NetWorthVisitor();
            var incomeVisitor   = new IncomeVisitor();

            person.Accept(netWorthVisitor);
            person.Accept(incomeVisitor);

            Console.WriteLine(netWorthVisitor.Total);
            Console.WriteLine(incomeVisitor.Amount);
            Console.ReadLine();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Person person = new Person();

            person.getAssets().Add(new BankAccount(1000, 0.01));
            person.getAssets().Add(new BankAccount(2000, 0.02));
            person.getAssets().Add(new RealEstate(79000, 500));
            person.getAssets().Add(new Loan(40000, 40));

            NetWorthVisitor netWorthVisitor = new NetWorthVisitor();
            IncomeVisitor   incomeVisitor   = new IncomeVisitor();

            person.accept(netWorthVisitor);
            person.accept(incomeVisitor);

            Console.WriteLine(netWorthVisitor.getTotal());
            Console.WriteLine(incomeVisitor.getAmount());
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        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();
        }