static void Main(string[] args) { var mobilePhoneFactory = new MobilePhoneFactory(); IMobilePhone mobilePhoneApple = mobilePhoneFactory.GetMobilePhone(MobilePhoneType.Apple); mobilePhoneApple.DisplayInfo(); IMobilePhone mobilePhoneSamsung = mobilePhoneFactory.GetMobilePhone(MobilePhoneType.Samsung); mobilePhoneSamsung.DisplayInfo(); }
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(); }
static void Main(string[] args) { // HR New Employee Process IDeviceFactory factory = new SamsungFactory(); IMobilePhone phone = factory.CreateMobilePhone(); phone.Call("+45 12345678"); ITablet tablet = factory.CreateTablet(); tablet.PowerOn(); tablet.PowerOff(); }
public IMobilePhone GetMobilePhone(MobilePhoneType type) { IMobilePhone mobilePhone = null; switch (type) { case MobilePhoneType.Apple: mobilePhone = new Apple(); break; case MobilePhoneType.Samsung: mobilePhone = new Samsung(); break; } return(mobilePhone); }
static void Main(string[] args) { Console.WriteLine("Are you an apple fangirl?"); var isFangirl = Console.ReadLine() == "yes" ? true : false; ITechnologyAbstractFactory techFactory = null; if (isFangirl) { techFactory = new AppleFactory(); } else { techFactory = new SamsungFactory(); } IMobilePhone myphone = techFactory.CreatePhone(); ITablet mytablet = techFactory.CreateTablet(); }
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); }
public MobileClient(IMobilePhone mobilePhone) { _normalPhone = mobilePhone.GetNormalPhone(); _smartPhone = mobilePhone.GetSmartPhone(); }
public Human(IMobilePhone mobilePhone) { _mobilePhone = mobilePhone; }
public MobileClient(IMobilePhone factory) { smartPhone = factory.GetSmartPhone(); normalPhone = factory.GetNormalPhone(); }
public static void InterfaceTest() { A a = new A(); //class A B b = new B(); //class B a.aTest(); a.DialNumber(); a.ReceiveCall(); a.EndCall(); b.aTest(); b.DialNumber(); b.ReceiveCall(); b.EndCall(); IMobilePhone iA = (IMobilePhone)a; //interface iA.DialNumber(); iA.ReceiveCall(); iA.EndCall(); IMobilePhone iB = (IMobilePhone)b; iB.DialNumber(); iB.ReceiveCall(); iB.EndCall(); MyFather f = new MyFather(); MyMother m = new MyMother(); f.Name = "James"; m.Name = "Jennifer"; Console.WriteLine("My {0} is {1}", f.ParentTitle(), f.Name); Console.WriteLine("My {0} is {1}", m.ParentTitle(), m.Name); Childer c = new Childer(); c.Name = "Sophy"; c.title = "Father"; c.parentName = "Jame"; Console.WriteLine("{2}'s {0} is {1}", c.ParentTitle(), c.ParentName(), c.Name); iFive obj = new OddEven(); //iFive (small) OddEven (bigger) obj.One(); obj.Three(); obj.Five(); iEven obj1 = new OddEven(); obj1.Two(); obj1.Four(); ILog log = new ConsoleLog(); ILog log1 = new FileLog(); log.Log("sending log to console"); log1.Log("write log to log.txt"); infDemo.infDemoTest(); //public static method }
public MobileAbstractFactory(IMobilePhone factory) { smartPhone = factory.GetSmartPhone(); normalPhone = factory.GetNormalPhone(); }
public Person(IMobilePhone imobilephone) { _iMobilePhone = imobilephone; }
public Client(IMobilePhone factory) { _smartPhone = factory.GetSmartPhone(); _oldPhone = factory.GetOldPhone(); }
internal CMobilePhone(CItem parent, IMedDataSource dataSource) : base(parent, dataSource) { this.MobilePhone = (IMobilePhone)dataSource; }