Example #1
0
        static void Main(string[] args)
        {
            AbstractClass abstractClass = new ConcreteClass1();

            abstractClass.TemplateMethod();
            abstractClass = new ConcreteClass2();
            abstractClass.TemplateMethod();
        }
Example #2
0
        static void Main(string[] args)
        {
            AbstractClass abstractClass1 = new ConcreteClass1();
            AbstractClass abstractClass2 = new ConcreteClass2();

            abstractClass1.Operate();
            Console.WriteLine();
            abstractClass2.Operate();
        }
Example #3
0
        static void Main(string[] args)
        {
            AbstractClass class1 = new ConcreteClass1();
            AbstractClass class2 = new ConcreteClass2();

            //调用模版方法
            class1.templateMethod();
            class2.templateMethod();
            Console.ReadLine();
        }
Example #4
0
        static void Main(string[] args)
        {
            AbstractClass concreteclass1 = new ConcreteClass1();

            concreteclass1.TemplateMethod();

            AbstractClass concreteclass2 = new ConcreteClass2();

            concreteclass2.TemplateMethod();
        }
Example #5
0
        /// <summary>
        /// 模板方法:把不变的行为放到模板抽象类中,去除子类中重复的代码
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            //利用多态性:声明的是父类,实例化子类。
            AbstractClass cc1 = new ConcreteClass();

            cc1.Template();
            cc1 = new ConcreteClass2();
            cc1.Template();

            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            // use ConcreteClass1 operation to do TemplateMethod
            var concrete1 = new ConcreteClass1();

            concrete1.TemplateMethod();

            // use ConcreteClass2 operation to do TemplateMethod
            var concrete2 = new ConcreteClass2();

            concrete2.TemplateMethod();
        }