static void Main(string[] args) { Console.WriteLine("ENTER TO CONTINUE TO NEXT PATTERN..\n1 = Factory Method\n2 = Singleton"); List <Car> cars = new List <Car>(); CarFactory factory = new CarFactory(); cars.Add(factory.GetCar(CarType.Compact, "Peugotje", "Peugot")); cars.Add(factory.GetCar(CarType.Motorcycle, "Hondatje", "Honda")); cars.Add(factory.GetCar(CarType.Sports, "Lambotje", "Lambo")); foreach (Car c in cars) { Console.WriteLine(c); Console.WriteLine(c.Sound() + "\n"); } Console.ReadLine(); GameApplication appl = GameApplication.GetInstance(); appl.Name = "Pakimon Go"; Console.WriteLine(appl); //Using the default constructor doesn't work for the GameApplication class! Neither does inheriting from this class work. Console.ReadLine(); AppleFactory appleFactory = new AppleFactory(); Console.WriteLine(appleFactory.GetFood()); BananaFactory bananaFactory = new BananaFactory(); Console.WriteLine(bananaFactory.GetFood()); Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); //小米工厂生产 ProductFactory xiaomi = new MiFactory(); PadProduct mipad = xiaomi.CreatePad(); mipad.Print(); PhoneProduct miphone = xiaomi.CreatePhone(); miphone.Print(); //苹果工厂生产 ProductFactory apple = new AppleFactory(); PadProduct ipad = apple.CreatePad(); ipad.Print(); PhoneProduct iphone = apple.CreatePhone(); iphone.Print(); //当有新的公司时(Nexus) //创建 NexusFactory:继承工厂基类,实现创建pad产品、phone产品方法 //创建 NexusPad:继承Pad产品基类,实现Pad产品信息 //创建 NexusPhone:继承Phone产品基类,实现Phone产品信息 Console.ReadKey(); }
static void Main(string[] args) { FruitFatory fruitFatory = new AppleFactory(); Fruit fruit = fruitFatory.GetFruit(); fruit.MethodSame(); fruit.MethodDiff(); }
static void Main(string[] args) { IMobileFactory mobileFactory = new AppleFactory(); IMobile mobile = mobileFactory.GetMobile(ModelTypes.AppleIphone12); mobile.GetMobile(); Console.ReadKey(); }
public void OsTestApple(int w, int h, ArrayList add, string name) { DeviceFactory Factory = new AppleFactory(name); var Phone = Factory.CreatePhone(w, h, add); var result = "IOS"; Assert.AreEqual(result, Phone.OS); }
public void Main() { ConcretePhoneFactory concretePhoneFactory = new AppleFactory(); ProducePhone producePhone = new ProducePhone(concretePhoneFactory); producePhone.MountMotherBoard(); producePhone.MountCamera(); ConcretePhoneFactory concretePhoneFactory2 = new SamsungFactory(); ProducePhone producePhone2 = new ProducePhone(concretePhoneFactory); producePhone2.MountMotherBoard(); producePhone2.MountCamera(); }
static void Main(string[] args) { // HR New Employee Process IDeviceFactory factory = new AppleFactory(); // <-- Only(!) reference to vendor IMobilePhone phone = factory.CreateMobilePhone(); phone.Call("+45 12345678"); ITablet tablet = factory.CreateTablet(); tablet.PowerOn(); tablet.PowerOff(); }
public void TestCreatePhablet() { LumiaPhab phablet = new LumiaPhab(); AbstractFactory nokia = new NokiaFactory(); Assert.AreSame(phablet.GetType(), nokia.createPhablet().GetType()); GalaxyNote samsungphablet = new GalaxyNote(); AbstractFactory samsung = new SamsungFactory(); Assert.AreSame(samsungphablet.GetType(), samsung.createPhablet().GetType()); iPhonePlus applephablet = new iPhonePlus(); AbstractFactory apple = new AppleFactory(); Assert.AreSame(applephablet.GetType(), apple.createPhablet().GetType()); }
public void TestCreateTablet() { iPad tablet = new iPad(); AbstractFactory apple = new AppleFactory(); Assert.AreSame(tablet.GetType(), apple.createTablet().GetType()); LumiaTab nokiatablet = new LumiaTab(); AbstractFactory nokia = new NokiaFactory(); Assert.AreSame(nokiatablet.GetType(), nokia.createTablet().GetType()); GalaxyTab samsungtablet = new GalaxyTab(); AbstractFactory samsung = new SamsungFactory(); Assert.AreSame(samsungtablet.GetType(), samsung.createTablet().GetType()); }
public void TestCreatePhone() { GalaxyMini phone = new GalaxyMini(); AbstractFactory samsung = new SamsungFactory(); Assert.AreSame(phone.GetType(), samsung.createPhone().GetType()); iPhone applephone = new iPhone(); AbstractFactory apple = new AppleFactory(); Assert.AreSame(applephone.GetType(), apple.createPhone().GetType()); Lumia nokiaphone = new Lumia(); AbstractFactory nokia = new NokiaFactory(); Assert.AreSame(nokiaphone.GetType(), nokia.createPhone().GetType()); }
static void Main(string[] args) { string techType = Console.ReadLine(); ITechnologyAbstractFactory abstractFactory = null; if (techType.ToLower() == "samsung") { abstractFactory = new SamsungFactory(); } else if (techType.ToLower() == "apple") { abstractFactory = new AppleFactory(); } IMobilePhone mobilePhone = abstractFactory.CreatePhone(); ITablet tablet = abstractFactory.CreateTablet(); Console.WriteLine(mobilePhone.GetType().Name); Console.WriteLine(tablet.GetType().Name); }
private void AbstractFactoryModeTest() { //小米工厂生产 AbstractFactory xiaomiFactory = new XiaoMiFactory(); MotherBoard xiaomiMotherBoard = xiaomiFactory.CreateMotherBoard(); xiaomiMotherBoard.Print(); Screen xiaomiScreen = xiaomiFactory.CreateScreen(); xiaomiScreen.Print(); //苹果生产 AbstractFactory appFactory = new AppleFactory(); Screen appleScreen = appFactory.CreateScreen(); appleScreen.Print(); MotherBoard motherBoard = appFactory.CreateMotherBoard(); motherBoard.Print(); Console.ReadKey(); }
public static ISmartphoneFactory GetSmartphoneFactory(SmartphoneFactoryType type, ILogger logger) { ISmartphoneFactory factory = null; switch (type) { case SmartphoneFactoryType.AppleFactory: factory = new AppleFactory(logger); break; case SmartphoneFactoryType.SamsungFactory: factory = new SamsungFactory(logger); break; case SmartphoneFactoryType.XiaomiFactory: factory = new XiaomiFactory(logger); break; default: break; } return(factory); }
void Start() { IFactory factory = new AppleFactory(); factory.Make().MakePhone(); }