static void UsePhone(object obj) { Console.ReadLine(); IPhoneInterface lance = (IPhoneInterface)obj; PhoneBooth spear = (PhoneBooth)obj; Tardis glaive = (Tardis)obj; lance.MakeCall(); lance.HangUp(); if (lance == spear) { spear.OpenDoor(); } if (obj == glaive) { glaive.TimeTravel(); } }
static void UsePhone(object obj) { Phone phone = (Phone)obj; IPhoneInterface iphoneInterface = null; phone.MakeCall(); phone.HangUp(); if (phone.GetType() == typeof(Tardis)) { iphoneInterface = (IPhoneInterface)phone; phone.TimeTravel(); } if (phone.GetType() == typeof(PhoneBooth)) { iphoneInterface = (IPhoneInterface)phone; phone.OpenDoor(); } }
public PhoneFactory(IPhoneInterface phoneInterface) { _phoneInterface = phoneInterface; }