private Vehicle CreateVehicle(XElement element) { Vehicle vehicle = null; switch (element.Name.ToString()) { case "Benz": vehicle = new Benz(); break; case "Honda": vehicle = new Honda(); break; case "Ferrari": vehicle = new Ferrari(); break; default: break; } vehicle.Name = (string)element.Element("Name"); vehicle.Text = vehicle.Name; return(vehicle); }
public void DriverTest() { ICar benz = new Benz(); //san 开奔驰 mockDriver.Object.driver(benz); mockDriver.Verify(t => t.driver(It.IsAny <ICar>()), Times.Once); }
static void Main() { Director director = new Director(); Builder bmw = new Bmw(); Builder benz = new Benz(); director.Create(bmw).GetResult().Show(); director.Create(benz).GetResult().Show(); }
static void Main() { Benz benz = new Benz(CarType.전기); benz.Go(); Console.WriteLine($"{benz.Style}"); Future future = new Future(); future.Go(); Console.WriteLine("되나"); }
/* * 生产汽车方法 */ public Car getCar(String type) { Car c = null; if ("BMW".Equals(type)) //判断顾客是需要那样的汽车 { c = new BMW(); //生产宝马汽车 } else if ("Benz".Equals(type)) { c = new Benz(); //生产奔驰 } return(c); }
/// <summary> /// 生产汽车 /// </summary> /// <returns></returns> public ICar CreateCar() { ICar car = null; switch (name.ToLower()) { case "audi": car = new Audi(); break; case "benz": car = new Benz(); break; } return(car); }
static void Main() //入口方法 { Car bmw = new BM(); //基类对象引用子类实例,创建Car对象 Car benz = new Benz(); //基类对象引用子类实例,创建Car对象 Car hongqi = new HongQi(); //基类对象引用子类实例,创建Car对象 List <Car> LCar = new List <Car>(); //创建集合对象 LCar.Add(bmw); //向集合添加Car对象 LCar.Add(benz); //向集合添加Car对象 LCar.Add(hongqi); //向集合添加Car对象 foreach (Car c in LCar) //遍历集合 { c.Run(); //执行Run方法 } Console.ReadLine(); //等待回车继续 }
static void Main(string[] args) { IFastCarCollection fastCarCollection = new FastCarCollection(); FastCar lamborghini = new Lamborghini(); FastCar bmw = new Bmw(); FastCar benz = new Benz(); fastCarCollection.Attach(lamborghini); fastCarCollection.Attach(bmw); fastCarCollection.Attach(benz); ICarCostomer normalCostomer = new NormalCostomer(); ICarCostomer vipCostomer = new VipCostomer(); fastCarCollection.Accept(normalCostomer); //fastCarCollection.Detach(bmw); fastCarCollection.Accept(vipCostomer); }
/* * 生产汽车方法 */ public Car getCar(String type) { Car c = null; if ("BMW".Equals(type)) //判断顾客是需要那样的汽车 { c = new BMW(); //生产宝马汽车 } else if ("Benz".Equals(type)) { c = new Benz(); //生产奔驰 } return c; }