static void Main(string[] args) { #region 基本用法(对应Basic.cs) AbstractClass c; c = new ConcreteClassA(); c.TemplateMethod(); c = new ConcreteClassB(); c.TemplateMethod(); #endregion #region 具体实例(对应Example.cs) Console.WriteLine("学生甲抄的试卷:"); TestPaper studentA = new TestPaperA(); studentA.TestQuestion1(); studentA.TestQuestion2(); studentA.TestQuestion3(); Console.WriteLine("学生乙抄的试卷:"); TestPaper studentB = new TestPaperB(); studentB.TestQuestion1(); studentB.TestQuestion2(); studentB.TestQuestion3(); Console.Read(); #endregion }
static void Main(string[] args) { AbstractClass abstractClass = new ConcreteClassA(); abstractClass.Launch(); abstractClass = new ConcreteClassB(); abstractClass.Launch(); Console.Read(); }
static void Main() { AbstractClass a = new ConcreteClassA(); a.TemplateMethod(); AbstractClass b = new ConcreteClassB(); b.TemplateMethod(); Console.ReadKey(); }
static void Main(string[] args) { AbstractClass a = new ConcreteClassA(); a.TemplateMethod(); a = new ConcreteClassB(); a.TemplateMethod(); int[] intArray = new int[] { 5, 3, 12, 8, 10 }; IntBubbleSorter intBubbleSorter = new IntBubbleSorter(); intBubbleSorter.Sort(intArray); foreach (var item in intArray) { Console.Write(item + " "); } Console.WriteLine(""); float[] floatArray = new float[] { 5.1f, 3.1f, 12.1f, 8.1f, 10.1f }; FloatBubbleSorter floatSorter = new FloatBubbleSorter(); floatSorter.Sort(floatArray); foreach (float item in floatArray) { Console.Write(item + " "); } string subClassStr = ConfigurationManager.AppSettings["subClass"]; var intBubbleSorter2 = (IntBubbleSorter)Assembly.Load("TemplateMethod").CreateInstance(subClassStr); intBubbleSorter2.Sort(intArray); Console.Read(); }