예제 #1
0
        public void StrategyTest()
        {
            {
                var content = new Context();
                content.AlgorithmInvoker();
                content.SetStrategy(new ConcreteStrategyA());
                content.AlgorithmInvoker();
                content.SetStrategy(new ConcreteStrategyB());
                content.AlgorithmInvoker();
            }
            {
                var operation = new InterestOperation();
                operation.SetStragety(new PersonalTaxStrategy());
                Console.WriteLine("个人支付的税为{0}", operation.GetTax(5000));

                operation.SetStragety(new EnterpriseTaxStrategy());
                Console.WriteLine("企业支付的税为{0}", operation.GetTax(50000));
            }
            {
                var duck = new RedDuck();
                duck.PerFormFly();
                duck.PerFormQuack();

                var rubberDuck = new RubberDuck();
                rubberDuck.PerFormFly();
                rubberDuck.PerFormQuack();
            }
            {
                var content = new 策略模式.抽题.GetExamContext(10);
                content.AddStrategy(new GetOneMonthExamStrategy());
                content.AddStrategy(new GetTwoMonthExamStrategy());
                content.GetExam();
            }
        }