Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading;
- using System.Linq;
- class Program
- {
- static void Main(string[] args)
- {
- IFigure rectangle = new Rectangle(10, 10);
- IFigure cloneRectangle = rectangle.Clone();
- Console.WriteLine("Прототип");
- rectangle.GetInfo();
- Console.WriteLine("Клон");
- cloneRectangle.GetInfo();
- IFigure circle = new Circle(50);
- IFigure cloneCircle = circle.Clone();
- Console.WriteLine("Круг");
- circle.GetInfo();
- Console.WriteLine("Клон");
- cloneCircle.GetInfo();
- Console.ReadLine();
- }
- }
- interface IFigure
- {
- IFigure Clone();
- void GetInfo();
- }
- class Rectangle: IFigure
- {
- int width;
- int height;
- public Rectangle(int w, int h)
- {
- this.width = w;
- this.height = h;
- }
- public IFigure Clone()
- {
- return new Rectangle(this.width, this.height);
- }
- public void GetInfo()
- {
- Console.WriteLine("Прямоугольник длиной {0} шириной {1}", this.height, this.width);
- }
- }
- class Circle: IFigure
- {
- int radius;
- public Circle(int r)
- {
- this.radius = r;
- }
- public IFigure Clone()
- {
- return new Circle(this.radius);
- }
- public void GetInfo()
- {
- Console.WriteLine("Круг радиусом {0}", this.radius);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement