예제 #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
            {
            }
        }
예제 #2
0
        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();
            }
        }
예제 #3
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();
            }
        }