Exemplo n.º 1
0
        static void UsePhone(PhoneInterface phone)
        {
            phone.MakeCall();
            phone.HangUp();

            //calls OpenDoor if a PhoneBooth
            try
            {
                PhoneBooth tester = (PhoneBooth)phone;
                tester.OpenDoor();
            }
            catch
            {
            }

            //calls TimeTravel if Tardis
            try
            {
                Tardis tester = (Tardis)phone;
                tester.TimeTravel();
            }
            catch
            {
            }
        }
Exemplo n.º 2
0
        static void UsePhone(object obj)
        {
            PhoneInterface MyInterface = (PhoneInterface)obj;

            MyInterface.MakeCall();
            MyInterface.HangUp();



            if (obj.Equals(typeof(PhoneBooth)))
            {
                PhoneBooth myBooth = (PhoneBooth)obj;
                myBooth.openDoor();
            }
            if (obj.Equals(typeof(Tardis)))
            {
                Tardis mytardis = (Tardis)obj;
                mytardis.TimeTravel();
            }
        }