コード例 #1
0
        static void Main(string[] args)
        {
            Circle figure       = new Circle(30, 50, 60);
            Circle clonedFigure = figure.Clone() as Circle;

            //---------Example of deep copy
            figure.GetInfo();
            clonedFigure.GetInfo();

            figure.Radius = 1000;

            figure.GetInfo();
            clonedFigure.GetInfo();
            //---------Example of deep copy

            //---------Example of shalow copy
            //---------But class doesn't contain referense type
            Rectangle rectangle       = new Rectangle(20, 40);
            Rectangle clonedRectangle = rectangle.Clone() as Rectangle;

            rectangle.GetInfo();
            clonedRectangle.GetInfo();

            Console.ReadKey();
        }
コード例 #2
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
             */
        }
コード例 #3
0
        static void Main(string[] args)
        {
            IFigure figure       = new Rectangle(30, 40);
            IFigure clonedFigure = figure.Clone();

            figure.GetInfo();
            clonedFigure.GetInfo();

            figure       = new Circle(30);
            clonedFigure = figure.Clone();
            figure.GetInfo();
            clonedFigure.GetInfo();
        }
コード例 #4
0
        static void Main(string[] args)
        {
            IFigure figure       = new Rectangle(30, 40);
            IFigure clonedFigure = figure.Clone();

            figure.GetInfo();
            clonedFigure.GetInfo();

            Circle figure1       = new Circle(5, 4, 2);
            Circle clonedFigure1 = figure1.Clone() as Circle;

            figure1.GetInfo();
            clonedFigure1.GetInfo();
            Console.ReadKey();
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: YuraOnyfrak/Pattern
        static void Main(string[] args)
        {
            IFigure figure      = new Rectangle(12, 12);
            IFigure figureClone = figure.Clone();

            figure.GetInfo();
            figureClone.GetInfo();


            figure      = new Circle(30);
            figureClone = figure.Clone();
            figure.GetInfo();
            figureClone.GetInfo();

            Console.ReadLine();
        }
コード例 #6
0
ファイル: Prototype.cs プロジェクト: Afformativ/HomeWork6
        static void Main(string[] args)
        {
            IFigure figure       = new Rectangle(10, 20);
            IFigure clonedFigure = figure.Clone();

            figure.GetInfo();
            clonedFigure.GetInfo();
            figure       = new Circle(15);
            clonedFigure = figure.Clone();
            figure.GetInfo();
            clonedFigure.GetInfo();
            figure       = new Triangle(10, 20, 25);
            clonedFigure = figure.Clone();
            figure.GetInfo();
            clonedFigure.GetInfo();
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: Ledrunning/DesignPatterns
        private static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Green;
            Console.Title           = "Prototype";

            IFigure figure       = new Rectangle(30, 40);
            var     clonedFigure = figure.Clone();

            figure.GetInfo();
            clonedFigure.GetInfo();

            figure       = new Circle(30);
            clonedFigure = figure.Clone();
            figure.GetInfo();
            clonedFigure.GetInfo();

            Console.ReadKey();
        }
コード例 #8
0
        private void PrototypeStart(object sender, RoutedEventArgs e)
        {
            IFigure figure       = new Prototype.Rectangle(30, 40);
            IFigure clonedFigure = figure.Clone();

            MessageBox.Show(figure.GetInfo());
            MessageBox.Show(clonedFigure.GetInfo());

            figure       = new Circle(30);
            clonedFigure = figure.Clone();
            MessageBox.Show(figure.GetInfo());
            MessageBox.Show(clonedFigure.GetInfo());

            figure = new Circle(15);
            MessageBox.Show(figure.GetInfo());
            Circle deepClonedFigure = figure.DeepCopy() as Circle;

            MessageBox.Show(deepClonedFigure.GetInfo());
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: Lucas-Sholtz/Patterns
        static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;

            IFigure figure       = new Rectangle(10, 20);
            IFigure clonedFigure = figure.Clone();

            figure.GetInfo();
            clonedFigure.GetInfo();

            figure       = new Circle(15);
            clonedFigure = figure.Clone();
            figure.GetInfo();
            clonedFigure.GetInfo();

            figure       = new Triangle(3, 4, 5);
            clonedFigure = figure.Clone();
            figure.GetInfo();
            clonedFigure.GetInfo();

            Console.Read();
        }
コード例 #10
0
        static void Main(string[] args)
        {
            IFigure figure       = new Rectangle(30, 40);
            IFigure clonedFigure = figure.Clone();

            ((Rectangle)clonedFigure).Point.X = 1;
            ((Rectangle)clonedFigure).Point.Y = 1;

            figure.GetInfo();
            clonedFigure.GetInfo();

            Console.WriteLine(new string('-', 52));

            figure       = new Rectangle(30, 40);
            clonedFigure = ((Rectangle)figure).DeepCopy() as IFigure;

            ((Rectangle)clonedFigure).Point.X = 1;
            ((Rectangle)clonedFigure).Point.Y = 1;

            figure.GetInfo();
            clonedFigure.GetInfo();

            Console.Read();
        }