示例#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();
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            //creating object of white duck
            Duck d = new WhiteDuck();

            d.Fly();
            d.Fb = new FlySlow();

            d.Quack();
            d.Fly();

            //creating object of red duck
            d = new RedDuck();
            d.Fly();
            d.Quack();

            //creating object of rubber duck
            d = new RubberDuck();
            d.Fly();
            d.Quack();

            //creating object of wooden duck
            d = new WoodenDuck();
            d.Fly();
            d.Quack();



            Console.ReadKey();
        }