コード例 #1
0
        static void Main(string[] args)
        {
            Circle circle1 = new Circle(10);
            Circle circle2;

            circle2 = (Circle)circle1.clone();

            circle1.GetInfo();
            circle2.GetInfo();


            Rectangle rectangle1 = new Rectangle(10, 3);
            Rectangle rectangle2;

            rectangle2 = (Rectangle)rectangle1.clone();

            rectangle1.GetInfo();
            rectangle2.GetInfo();

            /* OUTPUT
             * Shape of this Circle: 10
             * Shape of this Circle: 10
             * Shape of this Rectangle: 2x3
             * Shape of this Rectangle: 2x3
             */
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: Ofril/DesignPatterns
        static void Main(string[] args)
        {
            Circle      c           = new Circle(new Point(5, 5), 50.5);
            Rectangle   r           = new Rectangle(new Point(0, 0), new Point(0, 5), new Point(5, 0), new Point(5, 5));
            ShapeHolder shapeHolder = new ShapeHolder();

            Console.WriteLine(c);
            Console.WriteLine(r);

            DoStuffWithCircle((Circle)c.clone());
            DoStuffWithRectangle((Rectangle)r.clone());

            Console.WriteLine(c);
            Console.WriteLine(r);

            shapeHolder.addShape(c);
            shapeHolder.addShape(r);

            Console.WriteLine(shapeHolder.clone());
        }