Beispiel #1
0
        static void Main(string[] args)
        {
            Hexagon hex = new Hexagon("Beth");
            hex.Draw();

            Circle cir = new Circle("Cindy");
            // Calls base class implementation
            cir.Draw();

            // Make an array of Shape-compatible objects
            Shape[] myShapes = {new Hexagon(), new Circle(), new Hexagon("Mick")
                              , new Circle("Beth"), new Hexagon("Linda")};
            // Loop over each item and interact with the polymorphic interface
            foreach (Shape s in myShapes) {
                s.Draw();
            }

            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Polymorphism *****\n");

            Hexagon hex = new Hexagon("Beth");
            hex.Draw();

            Circle cir = new Circle("Cindy");
            // Calls base class implementation!
            cir.Draw();
            Console.WriteLine();

            // Make an array of Shap-compatible objects.
            Shape[] myShapes = {new Hexagon(), new Circle(), new Hexagon("Mick"), new Circle("Beth"), new Hexagon("Linda")};

            // Loop over each item and interact with
            // Polymorphic interface.
            foreach (Shape s in myShapes)
            {
                s.Draw();
            }

            Console.WriteLine();

            // This calls the Draw() method of the ThreeDCircle.
            ThreeDCircle o = new ThreeDCircle();
            o.Draw();

            DrawCircle(o);
            Console.WriteLine();

            // This calls the Draw() method of the parent!
            ((Circle)o).Draw();

            Circle oCopy = o as Circle;
            oCopy.Draw();
            Console.WriteLine();

            Console.ReadKey();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            Hexagon hex = new Hexagon("Beth");
            hex.Draw();

            Circle cir = new Circle("Cindy");
            cir.Draw();

            Shape[] myShapes = { new Hexagon(), new Circle(), new Hexagon("Mick"), new Circle("Beth"), new Hexagon("Linda") };

            foreach (Shape s in myShapes)
            {
                s.Draw();
            }

            ThreeDCircle o = new ThreeDCircle();
            o.Draw();

            ((Circle)o).Draw();

            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            Hexagon hex = new Hexagon("Beth");
            hex.Draw();

            Circle cir = new Circle("Cindy");
            cir.Draw();
            Console.WriteLine();

            Shape[] myShapes = { new Hexagon(), new Circle(), new Hexagon("Mick"), new Circle("Beth"), new Hexagon("Linda") };
            foreach (Shape s in myShapes)
            {
                s.Draw();
            }

            Console.WriteLine();
            ThreDCircle c = new ThreDCircle();
            c.Draw();                                 //calls method form 3d circle

            Circle c1 = new ThreDCircle();
            c1.Draw();                                //calls method form  circle
            Console.ReadLine();
        }