Ejemplo 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
            {
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Tardis     tard = new Tardis();
            PhoneBooth pb   = new PhoneBooth();

            UsePhone(tard);
            UsePhone(pb);
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            Tardis     myTardis = new Tardis();
            PhoneBooth myBooth  = new PhoneBooth();

            UsePhone(myBooth);
            UsePhone(myTardis);
        }
Ejemplo n.º 4
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();
            }
        }