Beispiel #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            ScaryScary  fingersTheClown     = new ScaryScary("big shoes", 14);
            FunnyFunny  someFunnyClown      = fingersTheClown;
            IScaryClown someOtherScaryClown = someFunnyClown as ScaryScary;

            someOtherScaryClown.Honk();
        }
Beispiel #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            ScaryScary  Clown1     = new ScaryScary("大鞋", 14);
            FunnyFunny  funnyClown = Clown1;
            IScaryClown Clown2     = funnyClown as ScaryScary;

            Clown2.Honk();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            ScaryScary  fingersTheClown     = new ScaryScary("bigshoes", 14);
            FunnyFunny  someFunnyClown      = fingersTheClown;
            IScaryClown someOtherScaryClown = someFunnyClown as ScaryScary;

            someOtherScaryClown.Honk();
            Console.ReadKey();
        }
Beispiel #4
0
        private void button3_Click(object sender, EventArgs e)
        {
            ScaryScary  fingersTheClown     = new ScaryScary("big shoes", 14, "spider");
            FunnyFunny  someFunnyClown      = fingersTheClown;
            IScaryClown someOtherScaryClown = someFunnyClown as ScaryScary;

            someOtherScaryClown.Honk();
            someOtherScaryClown.ScareLittleChildren();
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            ScaryScary  fingersTheClown     = new ScaryScary("duże buty", 35);
            FunnyFunny  someFunnyClown      = fingersTheClown;
            IScaryClown someOtherScaryClown = someFunnyClown as ScaryScary; // Thanks to the interfaces, now we can use  all methods and fields. In this way our funny clown can be scary as well.

            someOtherScaryClown.Honk();
            System.Console.Read();
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            ScaryScary  fingersTheClown     = new ScaryScary("duże buty", 14);
            FunnyFunny  someFunnyClown      = fingersTheClown;
            IScaryClown someOtherScaryClown = someFunnyClown as ScaryScary;

            someOtherScaryClown.Honk();
            Console.WriteLine(someOtherScaryClown.ScaryThingIHave);
            someOtherScaryClown.ScareLittleChildren();
            Console.ReadKey();
        }
Beispiel #7
0
        private void button1_Click(object sender, EventArgs e)
        {
            //TallGuy tallGuy = new TallGuy() { Name = "Drogo", Height=72};
            //tallGuy.TalkAboutYourself();

            ScaryClown  scary        = new ScaryClown("Facas", 13);
            FunnyFunny  funnyFunny   = scary;
            IScaryClown outroPalhaco = funnyFunny as ScaryClown;

            outroPalhaco.Honk();
        }
Beispiel #8
0
        private void button1_Click(object sender, EventArgs e)
        {
            ScaryScary  fingersTheClown     = new ScaryScary("Big shoes", 14);
            FunnyFunny  someFunnyClown      = fingersTheClown;
            IScaryClown someOtherScaryClown = someFunnyClown as ScaryScary;

            someOtherScaryClown.Honk();
            ScaryScary scary1 = new ScaryScary("Long nails", 12);

            scary1.ScareLittleChildren();
        }
Beispiel #9
0
        private void button2_Click(object sender, EventArgs e)
        {
            ScaryScary  FingersTheClown = new ScaryScary("大鼻子", 14);
            FunnyFunny  SomeFunnyClown  = FingersTheClown;
            IScaryClown SomeScaeyClown  = SomeFunnyClown as ScaryScary;

            /*  IScaryClown SomeScaeyClown 引用了 SomeFunnyClown (FunnyFunny) 但無法確認
             *  SomeFunnyClown 是否是 ScaryScary 所以要用 as
             */
            SomeScaeyClown.Honk();
        }
Beispiel #10
0
        private void button1_Click(object sender, EventArgs e)
        {
            /*TallGuy tallguy = new TallGuy() { Height = 184, Name = "姚明"};
             * tallguy.TalkAboutYourself();
             */

            ScaryScary  fingersTheClown     = new ScaryScary("大鞋", 14);
            FunnyFunny  someFunnyClown      = fingersTheClown;
            IScaryClown someOtherScaryClown = someFunnyClown as ScaryScary;

            someOtherScaryClown.Honk();
        }
        static void Main(string[] args)
        {
            ScaryScary  fingersTheClown     = new ScaryScary("big shoes", 14);
            FunnyFunny  someFunnyClown      = fingersTheClown;
            IScaryClown someOtherScaryClown = someFunnyClown as IScaryClown;

            someOtherScaryClown.Honk();
            someOtherScaryClown.ScareLittleChildren();
            Console.ReadKey();

            //TallGuy tallguy = new TallGuy() { Name = "Jimmy", Height = 74 };
            //tallguy.TalkAboutYourself();
            //tallguy.Honk();
        }
Beispiel #12
0
        private void button2_Click(object sender, EventArgs e)
        {
            //solution A: this solution is used to show upcasting and downcasting
            ScaryScary  fingersTheClown     = new ScaryScary("big shoes", 14);
            FunnyFunny  someFunnyClown      = fingersTheClown;              //upcasting to FunnyFunny Class
            IScaryClown someOtherScaryClown = someFunnyClown as ScaryScary; //downcasting to IScaryClown interface

            //if (someFunnyClown is IScaryClown) //my solution 1 which is different to the book, using interface casting with "as IScaryClown"
            //{
            //IScaryClown someOtherScaryClown = someFunnyClown as IScaryClown;
            //someOtherScaryClown.Honk();
            //}

            //solution 2: just one statement is enough
            //IScaryClown someOtherScaryClown = new ScaryScary("big shoes", 14);
            someOtherScaryClown.Honk();
            //someFunnyClown.Honk();
        }
Beispiel #13
0
        static void Main(string[] args)
        {
            CoffeMaker coffee_maker = new CoffeMaker();
            Oven       oven         = new Oven();

            Appliance[] kitchenWare = new Appliance[3];
            kitchenWare[0] = coffee_maker;
            kitchenWare[1] = oven;
            kitchenWare[2] = new Microwave();

            foreach (Appliance consumer in kitchenWare)
            {
                Console.WriteLine("{0} {1}", consumer, consumer.PowerWeight);
                CoffeMaker cm = consumer as CoffeMaker;
                ICookFood  cf = consumer as ICookFood;
                if (cm != null)
                {
                    cm.MakeCoffee();
                }
                else
                {
                    cf.HeatUp();
                }

                /*if (consumer is CoffeMaker) {
                 *  //CoffeMaker cm = (CoffeMaker) consumer;
                 *  (consumer as CoffeMaker).MakeCoffee();
                 * }*/
            }
            /*-----------------------------------------*/

            ScaryScary  scaryClown     = new ScaryScary(" большие ботинки\n", 14);
            FunnyFunny  someFunnyClown = scaryClown;
            IScaryClown someScaryClown = someFunnyClown as ScaryScary;

            someScaryClown.Honk();
            Console.Write(someScaryClown.ScaryThingIHave + "\n");
            someScaryClown.ScareLittleChildren();

            Console.ReadKey();
        }
Beispiel #14
0
        static void Main(string[] args)
        {
            TallGuy tallGuy = new TallGuy()
            {
                Height = 74, Name = "Jimmy"
            };

            tallGuy.TalkAboutYourself();
            tallGuy.Honk();

            ScaryScary  fingersTheClown     = new ScaryScary("big shoes", 14);
            FunnyFunny  someFunnyClown      = fingersTheClown;
            IScaryClown someOtherScaryClown = someFunnyClown as ScaryScary;

            // Maintains `Honk` method though IScaryClown inheriting from IClown
            someOtherScaryClown.Honk();

            Console.WriteLine(someOtherScaryClown.ScaryThingIHave);
            someOtherScaryClown.ScareLittleChildren();

            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            TallGuy tallGuy = new TallGuy()
            {
                Name = "Flávio", Height = 1.87
            };

            tallGuy.ThalkAboutYourself();
            tallGuy.Honk();

            ScaryScary fingersTheClown = new ScaryScary("big shoes", 14);
            FunnyFunny someFunnyClown  = fingersTheClown;

            someFunnyClown.Honk();
            IScaryClown someOtherScaryClown = someFunnyClown as ScaryScary;

            string scaryThing = someOtherScaryClown.ScaryThingIHave;

            Console.WriteLine(scaryThing);
            someOtherScaryClown.ScaryLittleChildren();
            someOtherScaryClown.Honk();

            Console.ReadKey();
        }