static void Main(string[] args) { Console.WriteLine("Red:"); for (int i = 0; i < 3; i++) { Circle circle = (Circle)ShapeFactory.GetCircle("circle"); circle.SetColor("Red"); circle.Draw(); } Console.WriteLine("\r\nGreen:"); for (int i = 0; i < 3; i++) { Circle circle = (Circle)ShapeFactory.GetCircle("circle"); circle.SetColor("Green"); circle.Draw(); } Console.WriteLine("\r\nBlue:"); for (int i = 0; i < 3; ++i) { Circle circle = (Circle)ShapeFactory.GetCircle("circle"); circle.SetColor("Green"); circle.Draw(); } Console.WriteLine("\r\nOrange:"); for (int i = 0; i < 3; ++i) { Circle circle = (Circle)ShapeFactory.GetCircle("circle"); circle.SetColor("Orange"); circle.Draw(); } Console.WriteLine("\r\nBlack:"); for (int i = 0; i < 3; ++i) { Circle circle = (Circle)ShapeFactory.GetCircle("circle"); circle.SetColor("Black"); circle.Draw(); } Console.ReadKey(); }
//Use sharing to support large numbers of fine-grained objects efficiently. static void Main(string[] _) { var factory = new ShapeFactory(); var shape = factory.GetShape(nameof(Circle)); shape.GetShapeName(); shape = factory.GetShape(nameof(Circle)); shape.GetShapeName(); shape = factory.GetShape(nameof(Rectangle)); shape.GetShapeName(); shape = factory.GetShape(nameof(Rectangle)); shape.GetShapeName(); Console.WriteLine($"count: {factory.ShapeCount}"); Console.ReadKey(); }
public static void Run() { Console.WriteLine("\n Red color Circles "); for (int i = 0; i < 3; i++) { Circle circle = (Circle)ShapeFactory.GetShape("circle"); circle.SetColor("Red"); circle.Draw(); } Console.WriteLine("\n Green color Circles "); for (int i = 0; i < 3; i++) { Circle circle = (Circle)ShapeFactory.GetShape("circle"); circle.SetColor("Green"); circle.Draw(); } Console.WriteLine("\n Blue color Circles"); for (int i = 0; i < 3; ++i) { Circle circle = (Circle)ShapeFactory.GetShape("circle"); circle.SetColor("Green"); circle.Draw(); } Console.WriteLine("\n Orange color Circles"); for (int i = 0; i < 3; ++i) { Circle circle = (Circle)ShapeFactory.GetShape("circle"); circle.SetColor("Orange"); circle.Draw(); } Console.WriteLine("\n Black color Circles"); for (int i = 0; i < 3; ++i) { Circle circle = (Circle)ShapeFactory.GetShape("circle"); circle.SetColor("Black"); circle.Draw(); } Console.ReadKey(); }
static void Main(string[] args) { ShapeFactory shapeFactory = new ShapeFactory(); List <IShape> shapes = new List <IShape>(); shapes.Add(shapeFactory.getShape("Square")); shapes.Add(shapeFactory.getShape("Circle")); shapes.Add(shapeFactory.getShape("Circle")); shapes.Add(shapeFactory.getShape("Point")); shapes.Add(shapeFactory.getShape("Square")); shapes.Add(shapeFactory.getShape("Circle")); Random rand = new Random(); foreach (var shape in shapes) { int x = rand.Next(100); int y = rand.Next(100); shape.draw(x, y); } }
static void Main(string[] args) { ShapeFactory sf = new ShapeFactory(); IShape s = sf.GetShape("Rectangle"); s.Print(); s = sf.GetShape("Circle"); s.Print(); s = sf.GetShape("Circle"); s.Print(); s = sf.GetShape("Rectangle"); s.Print(); s = sf.GetShape("Circle"); s.Print(); Console.WriteLine("Total Objects created : " + sf.TotalObjectsCreated); Console.ReadLine(); }
static void Main(string[] args) { ShapeFactory factory = new ShapeFactory(); List <IShape> shapes = new List <IShape>(); int x = 0; int y = 0; shapes.Add(factory.GetShape("квадрат")); shapes.Add(factory.GetShape("круг")); shapes.Add(factory.GetShape("круг")); shapes.Add(factory.GetShape("точка")); shapes.Add(factory.GetShape("квадрат")); shapes.Add(factory.GetShape("круг")); shapes.Add(factory.GetShape("точка")); Random random = new Random(); foreach (var shape in shapes) { x = random.Next(100); y = random.Next(100); shape.Draw(x, y); } }
static void Main(string[] args) { var factory = new ShapeFactory(); var shape = factory.GetShape(nameof(Circle)); shape.GetShapeName(); shape = factory.GetShape(nameof(Circle)); shape.GetShapeName(); shape = factory.GetShape(nameof(Regtangle)); shape.GetShapeName(); shape = factory.GetShape(nameof(Regtangle)); shape.GetShapeName(); Console.WriteLine($"The total object count: {factory.ShapesCount}"); Console.ReadKey(); }
public Form1() { InitializeComponent(); factory = new ShapeFactory(); }