//Method: Main //Purpose: Create a Tardis object and PhoneBooth object and use both by calling UsePhone Method //Restrictions: None static void Main(string[] args) { Tardis tardis = new Tardis(); PhoneBooth phoneBooth = new PhoneBooth(); UsePhone(tardis); UsePhone(phoneBooth); }
//Method: UsePhone //Purpose: call MakeCall() and HangUp() using interface, then calls approprate method based on object type //Restrictions: None static void UsePhone(object obj) { PhoneInterface phoneInterface = (PhoneInterface)obj; phoneInterface.MakeCall(); phoneInterface.HangUp(); if (obj.GetType() == typeof(PhoneBooth)) { PhoneBooth phoneBooth = (PhoneBooth)obj; phoneBooth.OpenDoor(); } else if (obj.GetType() == typeof(Tardis)) { Tardis tardis = (Tardis)obj; tardis.TimeTravel(); } }