public static AbsCar CreateCar(CarType type) { AbsCar target = null; AbsCarFactory factory = null; switch (type) { case CarType.Benz: factory = new BenzFactory(); break; case CarType.Bmw: factory = new BmwFactory(); break; case CarType.Honda: factory = new HondaFactory(); break; default: break; } if (null == factory) { return(null); } target = factory.CreateCar(); return(target); }
public void BmwFactory_ManufactureBmwCar() { var sut = new BmwFactory(); var result = sut.ManufactureCar(); Assert.That(result.Name, Is.EqualTo("BMW")); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); BmwFactory bmwFactory = new BmwFactory(); OpelFactory opelFactory = new OpelFactory(); MercedesFactory mercedesFactory = new MercedesFactory(); DunyaMarkalari dunyaMarkalari = new DunyaMarkalari(bmwFactory); Console.WriteLine(String.Format("Araba Modeli:{0}, Jant Çapı:{1}", dunyaMarkalari.ArabaModeli(), dunyaMarkalari.JantCapi())); Console.WriteLine(Environment.NewLine); DunyaMarkalari dunyaMarkalari2 = new DunyaMarkalari(opelFactory); Console.WriteLine(String.Format("Araba Modeli:{0}, Jant Çapı:{1}", dunyaMarkalari2.ArabaModeli(), dunyaMarkalari2.JantCapi())); Console.WriteLine(Environment.NewLine); DunyaMarkalari dunyaMarkalari3 = new DunyaMarkalari(mercedesFactory); Console.WriteLine(String.Format("Araba Modeli:{0}, Jant Çapı:{1}", dunyaMarkalari3.ArabaModeli(), dunyaMarkalari3.JantCapi())); Console.Read(); }
public static void AbstractFactoryDemo() { var bmwFactory = new BmwFactory(); IAutomobile myCar = bmwFactory.CreateSportsCar(); myCar.IntroDuce(); Console.WriteLine(myCar.GetType().Name); }
static void Main(string[] args) { Console.WriteLine("Abstract Factory Mode"); CarFactory carFactory = new BenzFactory(); carFactory.CreateWindows(); carFactory.CreateWheels(); Console.WriteLine("Change Factory To BMWFactory"); carFactory = new BmwFactory(); carFactory.CreateWindows(); carFactory.CreateWheels(); }
public void Start() { // Abstract factory #1 AbstractFactory factory1 = new BmwFactory(); System.Console.Write($"{factory1.GetType().Name} uses: "); Client client1 = new Client(factory1); client1.Run(); // Abstract factory #2 AbstractFactory factory2 = new AudiFactory(); System.Console.Write($"{factory2.GetType().Name} uses: "); Client client2 = new Client(factory2); client2.Run(); }
private static void Case1() { IAutomobile mobile; TeslaFactory tesla = TeslaFactory.GetInstance(); mobile = tesla.Make(); mobile.Start(); mobile.Stop(); BmwFactory bmw = BmwFactory.GetInstance(); mobile = bmw.Make(); mobile.Start(); mobile.Stop(); AudiFactory audi = AudiFactory.GetInstance(); mobile = audi.Make(); mobile.Start(); mobile.Stop(); }
public static void Main() { IAutoFactory autoFactory = new BmwFactory(); IAuto auto = autoFactory.GetInstance(); }
static void Main(string[] args) { // AUDI CarFactory carFactory = new AudiFactory(); Console.WriteLine(); var audiCoupe = carFactory.CreateCoupe(); audiCoupe.GetName(); audiCoupe.GetMaxSpeed(); Console.WriteLine(); var audiLimousine = carFactory.CreateLimousine(); audiLimousine.GetName(); audiLimousine.HasAirCon(); Console.WriteLine(); var audiSuw = carFactory.CreateSuW(); audiSuw.GetName(); audiSuw.SetWheelSize(); // BMW carFactory = new BmwFactory(); Console.WriteLine(); var bmwCoupe = carFactory.CreateCoupe(); bmwCoupe.GetName(); bmwCoupe.GetMaxSpeed(); Console.WriteLine(); var bmwLimousine = carFactory.CreateLimousine(); bmwLimousine.GetName(); bmwLimousine.HasAirCon(); Console.WriteLine(); var bmwSuw = carFactory.CreateSuW(); bmwSuw.GetName(); bmwSuw.SetWheelSize(); Console.WriteLine(); // HONDA ICarFactory hondaFactory = new HondaFactory(); Console.WriteLine(); var hondaCoupe = hondaFactory.CreateCoupe(); hondaCoupe.GetName(); hondaCoupe.GetMaxSpeed(); Console.WriteLine(); var hondaLimousine = hondaFactory.CreateLimousine(); hondaLimousine.GetName(); hondaLimousine.HasAirCon(); Console.WriteLine(); var hondaSuw = hondaFactory.CreateSuW(); hondaSuw.GetName(); hondaSuw.SetWheelSize(); Console.WriteLine(); Console.ReadKey(); }