static void Main(string[] args) { Tardis mytardis = new Tardis(); PhoneBooth mybooth = new PhoneBooth(); UsePhone(mytardis); UsePhone(mybooth); }
static void UsePhone(object obj) { PhoneInterface phone = (PhoneInterface)obj; phone.MakeCall(); if (obj.GetType() == typeof(PhoneBooth)) { PhoneBooth booth = (PhoneBooth)obj; booth.OpenDoor(); } else if (obj.GetType() == typeof(Tardis)) { Tardis tardis = (Tardis)obj; tardis.TimeTravel(); } }