C#面向对象设计模式纵横谈——14 Template Method模板方法

主讲:李建忠

来源:http://www.microsoft.com/china/msdn/events/webcasts/shared/webcast/consyscourse/CsharpOOD.aspx

 

clip_image002

clip_image004

clip_image006

clip_image008

clip_image010

clip_image012

clip_image014

 

   1:  //框架开发者-先开发
   2:   
   3:  public abstract class Vehical    //表示汽车
   4:  {
   5:      protected abstract void startup();
   6:   
   7:      protected abstract void run();
   8:   
   9:      protected abstract void turn(int degree);
  10:   
  11:      protected abstract void strop();
  12:   
  13:      public void Test()
  14:      {
  15:        //...测试数据记录
  16:        startup();    //晚绑定——留给应用程序开发人员;扩展点
  17:   
  18:        //...测试数据记录
  19:        run();
  20:   
  21:        //...测试数据记录
  22:        turn();
  23:   
  24:        //...测试数据记录
  25:        strop();
  26:   
  27:        //...生成测试数据报表
  28:   
  29:      }
  30:  }
  31:   
  32:  class VehicalTestFramework
  33:  {
  34:      public static void DoTest(Vehical vehical)
  35:      {
  36:        
  37:      }
  38:  }
  39:   
  40:  //应用程序开发人员-晚开发
  41:   
  42:  public class hongqiCar:Vehical
  43:  {
  44:      public override void startup()
  45:      {
  46:          //...
  47:      }
  48:   
  49:      public override void run()
  50:      {
  51:          //...
  52:      }
  53:   
  54:      public override void turn(int degree)
  55:      {
  56:          //...
  57:      }
  58:   
  59:      public override void strop()
  60:      {
  61:          //...
  62:      }
  63:  }
  64:   
  65:  class App
  66:  {
  67:      public static void Main()
  68:      {
  69:          VehicalTestFramework.DoTest(new HongqiCar());
  70:      }
  71:  }

 

clip_image016

你可能感兴趣的:(template)