예제 #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Polymorphism *****\n");

            // 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.WriteLine("-------------");
            // This calls the Draw() method of the ThreeDCircle.
            ThreeDCircle threeDCircle = new ThreeDCircle();

            // o.ShapeName = "Many Facets";
            threeDCircle.Draw();

            // This calls the Draw() method of the parent!
            ((Circle)threeDCircle).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();

            // 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();
            }

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

            o.Draw();

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

            Console.ReadLine();
        }
예제 #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Polymorphism *****");

            Hexagon hex = new Hexagon("Beth");

            hex.Draw();
            Circle cir = new Circle("Cidny");

            cir.Draw();

            //Создадим массив объектов типа Shape
            Shape[] myShapes = { new Hexagon(), new Circle(), new Hexagon("Mick"), new Circle("Beth"), new Hexagon("Linda") };

            //Пройдем по всем элементам массива и
            //взаимодействуем с полиморфным массивом
            foreach (Shape shape in myShapes)
            {
                shape.Draw();
            }

            ThreeDCircle o = new ThreeDCircle();

            //Вызываем метод, определенный в ThreeDCircle
            o.Draw();

            //Вызываем метод, определенный в родительском классе, при помощи явного приведения!
            ((Circle)o).Draw();

            Console.ReadLine();
        }
예제 #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with polymorphism *****\n");
            //Hexagon hex = new Hexagon("Beth");
            //hex.Draw();
            //Circle cir = new Circle("Cindy");
            //cir.Draw();

            //an array of Shape-compatible objs
            //Shape[] myShapes = { new Hexagon(), new Circle(), new
            //        Hexagon("Mick"), new Circle("Beth"),new
            //        Hexagon("Linda")};
            //foreach (Shape s in myShapes)
            //{
            //    s.Draw();
            //}

            //this calls the Draw() method from ThreeDCircle
            ThreeDCircle o = new ThreeDCircle();
            o.Draw();
            //this calls the Draw() method from the parent class!
            ((Circle)o).Draw();

            Console.ReadLine();
        }
예제 #5
0
        static void Main(string[] args)
        {
            Console.WriteLine("*** Fun with abstract and virtual Class/methods ***");
            Circle cr = new Circle("Big circle");

            cr.Draw();

            Hexagon hx = new Hexagon("Little Hexagon");

            hx.Draw();
            Console.WriteLine();

            Shape[] MyShapes = { new Hexagon(), new Circle(), new Hexagon("Little"), new Circle("Big") };
            foreach (Shape i in MyShapes)
            {
                i.Draw();
            }
            Console.WriteLine();
            ThreeDCircle o = new ThreeDCircle();

            o.Draw();
            ((Circle)o).Draw();

            Console.ReadLine();
        }
예제 #6
0
        static void Main(string[] args)
        {
            Console.WriteLine("**** Fun with Polymorphism ****\n");
            Hexagon hex = new Hexagon("Beth");

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

            cir.Draw();
            Console.WriteLine("-----------------------------------");
            //Создать массив совместимых с Shape объектов
            Shape[] myShapes = { new Hexagon(), new Circle(), new Hexagon("Mick"), new Circle("Beth"), new Hexagon("Linda") };
            //Пройти цикл по каждому элементу и взаимодействовать с полиморфным интерфейсом
            foreach (Shape s in myShapes)
            {
                s.Draw();
            }
            Console.WriteLine("-----------------------------------");
            //Здесь вызывается метод Draw из класса ThreeDCircle
            ThreeDCircle o = new ThreeDCircle();

            o.Draw();
            //Здесь вызывается метод Draw() родителя!
            ((Circle)o).Draw();
            Console.ReadLine();
        }
예제 #7
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Polymorphism *****\n");
            Hexagon hex = new Hexagon("Beth");

            hex.Draw();

            Circle cir = new Circle(name: "Cindy");

            // Calls base class implementation!
            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();

            // This calls the Draw() method of the parent!   ((Circle)o).Draw();   Console.ReadLine();
        }
예제 #8
0
        public static void Main(string[] args)
        {
            Console.WriteLine(" Understanding Polymorphic Interface");
            Hexagon hex = new Hexagon("Beth");

            hex.Draw();

            Circle cir = new Circle("Cindy");

            cir.Draw();

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

            // Possibility to trigger the base class implementation of a shadowed member
            // using explict cast

            // This calls shadowed memeber
            ThreeDCircle o = new ThreeDCircle();

            o.Draw();

            // This calls the Draw method of the Parent

            ((Circle)o).Draw();
        }
예제 #9
0
        static void Main(string[] args)
        {
            Console.WriteLine("**** Fun with polymorphysm ****");
            Hexagon betty = new Hexagon("Betty");

            betty.Draw();

            Circle nikky = new Circle("Nikky");

            nikky.Draw();
            Console.WriteLine();

            Shape[] myShapes = { new Circle(), new Hexagon(), new Hexagon("Nikky"), new Circle("Betty"), new Hexagon("Jack") };
            foreach (Shape s in myShapes)
            {
                s.Draw();
            }
            Console.WriteLine();

            ThreeDCircle o = new ThreeDCircle();

            o.Draw();
            ((Circle)o).Draw();
            Console.ReadLine();
        }
예제 #10
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Polymorphism *****\n");

            // 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 (var s in myShapes)
            // {
            //     s.Draw();
            // }

            ThreeDCircle om = new ThreeDCircle();

            om.Draw();

            ((Circle)om).Draw();
            Console.WriteLine("Experiment:");
            Console.WriteLine(((Circle)om).PetName);
            Console.ReadLine();
        }
예제 #11
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Polymorphism *****\n");
            Hexagon hex = new Hexagon("Beth");

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

            // Calls base class implementation
            cir.Draw();
            Console.WriteLine();

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

            foreach (Shape s in myShapes)
            {
                s.Draw();
            }
            Console.WriteLine();
            ThreeDCircle d = new ThreeDCircle();

            ((Circle)d).Draw();
            d.Draw();
            Console.ReadLine();
        }
예제 #12
0
        static void Casting()
        {
            Console.ForegroundColor = ConsoleColor.DarkYellow;
            Console.WriteLine("=> Casting Rules");
            ThreeDCircle threed = new ThreeDCircle();

            Console.Write("Drawing via New Class: "); threed.Draw();
            Console.Write("Drawing via Base Class: "); ((Circle)threed).Draw();
        }
예제 #13
0
        static void Shadowing()
        {
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("=> Shadowing");

            ThreeDCircle threed = new ThreeDCircle();

            threed.Draw();
        }
예제 #14
0
        static void Main(string[] args)
        {
            ThreeDCircle o = new ThreeDCircle();

            o.Draw();
            //Вызов родительской реализации метода Draw
            ((Circle)o).Draw();
            Console.ReadLine();
        }
예제 #15
0
        static void Main(string[] args)
        {
            //Shape[] shapesOfObjects = { new Hexagon(), new Circle(), new Hexagon("Suri"), new
            //        Circle("Surendra")};

            //foreach(Shape shape in shapesOfObjects)
            //{
            //    shape.Draw();
            //}

            ThreeDCircle threeDCircle = new ThreeDCircle();

            threeDCircle.Draw();
        }
예제 #16
0
        static void Main(string[] args)
        {
            Console.WriteLine("*****Fun with Polymorphism *****/n");
            ThreeDCircle o = new ThreeDCircle();

            o.Draw();
            ((Circle)o).Draw();
            Shape[] myShapes = { new Hexagon(),      new Circle(), new Hexagon("Mick"),
                                 new Circle("Beth"), new Hexagon("Linda") };
            foreach (Shape s in myShapes)
            {
                s.Draw();
            }
            Console.ReadLine();
        }
예제 #17
0
        static void Main(string[] args)
        {
            Circle       fc           = new Circle("FirstCircle");
            Hexagon      fh           = new Hexagon("FirstHexagon");
            ThreeDCircle ThreeDCircle = new ThreeDCircle("3d Circle");

            object[] ArrC = new  object[5];

            object sc = new Circle("SecondCircle");



            ArrC[0] = fc;
            ArrC[1] = fh;
            ArrC[2] = ThreeDCircle;
            ArrC[3] = (Circle)sc;
            ArrC[4] = new ClassDontForThisProject();


            Console.WriteLine(fc.ToString());


            foreach (object s in ArrC)
            {
                if (s is Shape d)
                {
                    d.Draw();
                }
                else
                {
                    ClassDontForThisProject h = s as ClassDontForThisProject;
                    if (h == null)
                    {
                        Console.WriteLine("Не ClassDontForThisProject");
                    }
                    else
                    {
                        h.Learn();
                    }
                }
            }

            GetName((Circle)ArrC[0]);



            Console.ReadLine();
        }
예제 #18
0
        static void Main(string[] args)
        {
            Shape[] myShapes = { new Hexagon(),      new Circle(), new Hexagon("Mick"),
                                 new Circle("Beth"), new Hexagon("Linda") };
            foreach (var VARIABLE in myShapes)
            {
                VARIABLE.Draw();
            }

            ThreeDCircle o = new ThreeDCircle();

            o.Draw();
            //调用了父类的Draw()方法
            ((Circle)o).Draw();

            Console.ReadKey();
        }
예제 #19
0
        static void Main(string[] args)
        {
            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();

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

            Console.ReadLine();
        }
예제 #20
0
        static void Main(string[] args)
        {
            Console.WriteLine("**** Fun with Polymorphism *****\n");
            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();
        }
        // Create an array of various Shapes.
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Polymorphism *****\n");

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

            // Loop over the array and ask each object to draw itself.
            for (int i = 0; i < myShapes.Length; i++)
            {
                myShapes[i].Draw();
            }

            ThreeDCircle o = new ThreeDCircle();

            o.Draw();            // Calls ThreeDCircle.Draw()
            ((Circle)o).Draw();  // Calls Circle.Draw()

            Console.ReadLine();
        }
예제 #22
0
        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();
        }
예제 #23
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Polymorphism *****\n");

            // 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 items and interact with the
            // polymorphic interface.
            foreach (Shape s in myShapes)
            {
                s.Draw();
            }

            // Fun with shadowing.
            ThreeDCircle o = new ThreeDCircle();

            o.Draw();
            ((Circle)o).Draw();
            Console.ReadLine();
        }
예제 #24
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();
        }
예제 #25
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Polymorphism *****\n");
            // Создать массив совместных с Shape объектов.
            Shape[] myShapes = { new Hexagon(),      new Circle(), new Hexagon("Mick"),
                                 new Circle("Beth"), new Hexagon("Linda") };

            // Перейти в цикл по всем элементам и взаимодействовать
            // с полифорным интерфейсом.
            foreach (Shape s in myShapes)
            {
                s.Draw();
            }
            //здесь вызывается метод draw() из класса threedcircle.
            ThreeDCircle o = new ThreeDCircle();

            o.Draw();
            //здесь вызывается метод draw родительского класса!!
            ((Circle)o).Draw();


            Console.ReadLine();
        }
예제 #26
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun With Polymorphism *****");
            // Make an array of Shape-compatible objects
            Shape[] myShapes = { new Hexagon(), new Circle(), new Hexagon("Andre"), new Circle("Jane"),
                                 new Hexagon("Kate") };

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

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

            o.Draw();

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

            Console.ReadLine();
        }
예제 #27
0
파일: Program.cs 프로젝트: usedflax/flaxbox
        static void Main( string[] args )
        {
            Console.WriteLine("***** Fun with Polymorphism *****\n");

            // 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();
            }

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

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

            Console.ReadLine();
        }