static void Main(string[] args) { //申明工厂类 ICar benzFactory = new BenzFactory(); //工厂类创建具体类 ACar car = benzFactory.GetCar(); //使用获取的类的方法 car.OpenCar(); Console.Read(); }
public void TestMethod1() { IDriver driver = new Driver(); ICar acar = new ACar(); driver.ToDrive(acar); ICar bcar = new BCar(); driver.ToDrive(bcar); //共5行 }
public void TestMethod3() { ICar acar = new ACar(); ICar bcar = new ACar(); IDriver3 driver = new Driver3(); driver.SetCar(acar); driver.ToDrive(); driver.SetCar(bcar); driver.ToDrive(); //共7行代码 }
public void TestMethod2() { ICar acar = new ACar(); IDriver2 driver = new Driver2(acar); driver.ToDrive(); ICar bcar = new BCar(); IDriver2 driver2 = new Driver2(bcar); driver2.ToDrive(); //共6行代码 }
public override void Handle(ACar car) { Console.WriteLine("The car is stopped"); car.State = this; }
public abstract void Handle(ACar car);
public CommandStart(ACar car) : base(car) { }
public CommandMove(ACar car) : base(car) { }
// Constructor public ACommand(ACar car) { this.car = car; }
public CommandStop(ACar car) : base(car) { }
public override void Handle(ACar car) { Console.WriteLine("The engine is started, but the car isn't moving"); car.State = this; }