Factory Method模式的学习

using System;

namespace FactoryMethod
{
   abstract class AbstractCar
 {
  public abstract void Startup();
  public abstract void Run();
  public abstract void Turn();
  public abstract void Stop();
 }
 abstract class CarFactory
 {
  public abstract AbstractCar CreateCar();
 }

 /// <summary>
 /// ////////////////////////////////////////////////////
 /// </summary>
 
 public class Engiee
 {
 }
 class HongqiCar:AbstractCar
 {
  public Engiee engiee1;
  public Engiee engiee4;
  public Engiee engiee3;
  public Engiee engiee2;
  public override void Startup()
  {
  }
  public override void Run()
  {
  }
  public override void Turn()
  {
  }
  public override void Stop()
  {
  }
 }
 class HongqiCarFactory: CarFactory
 {
  public override AbstractCar CreateCar()
  {
   return new HongqiCar();
  }
 }

 /// <summary>
 /// ////////////////////////////////////////////一般不变(动态导向可以实现)
 /// </summary>
 class App
 {
  public static void Main()
  {
   CarTestFramework.BuildTestContext(new HongqiCarFactory());
  }
 }

 /// <summary>
 /// ////////////////////////////////////////主程序(主逻辑)永远不变
 /// </summary>
 class CarTestFramework
 {
  public static void BuildTestContext(CarFactory carFactory)
  {
   AbstractCar c1=carFactory.CreateCar();
   //...
  }
  public void DoTest(AbstractCar car)
  {
   //..
  }
  public void GetTestData(AbstractCar car)
  {
   //....
  }
 }
}

posted @ 2006-03-05 21:14  kuailewangzi1212  阅读(113)  评论(0编辑  收藏  举报