コード例 #1
0
        static void Main(string[] args)
        {
            object tardy  = new Tardis();
            object boxman = new PhoneBooth();

            UsePhone(tardy);
            UsePhone(boxman);
        }
コード例 #2
0
        static void UsePhone(object obj)
        {
            Console.ReadLine();
            IPhoneInterface lance  = (IPhoneInterface)obj;
            PhoneBooth      spear  = (PhoneBooth)obj;
            Tardis          glaive = (Tardis)obj;

            lance.MakeCall();
            lance.HangUp();

            if (lance == spear)
            {
                spear.OpenDoor();
            }
            if (obj == glaive)
            {
                glaive.TimeTravel();
            }
        }