static void Main(string[] args) { ShapeFactory shapeFactory = new ShapeFactory(); Shape shape1 = shapeFactory.GetShape("circle"); shape1.draw(); Shape shape2 = shapeFactory.GetShape("rectangle"); shape2.draw(); Shape shape3 = shapeFactory.GetShape("square"); shape3.draw(); }
static void Main(string[] args) { ShapeFactory shapeFactory = new ShapeFactory(); //get an object of Circle and call its draw method. Shape shape1 = shapeFactory.GetShape("CIRCLE"); //call draw method of Circle shape1.draw(); //get an object of Rectangle and call its draw method. Shape shape2 = shapeFactory.GetShape("RECTANGLE"); //call draw method of Rectangle shape2.draw(); //get an object of Square and call its draw method. Shape shape3 = shapeFactory.GetShape("SQUARE"); //call draw method of square shape3.draw(); }
static void Main(string[] args) { Console.WriteLine("Using Generic Method"); IShapeFactory shapeFactory = new ShapeFactory(); var shapes = new IShape[6]; shapes[0] = shapeFactory.CreateShape <Circle>(); shapes[1] = shapeFactory.CreateShape <Rectangle>(); shapes[2] = shapeFactory.CreateShape <NullShape>(); shapes[3] = shapeFactory.CreateShape <Square>(); shapes[4] = shapeFactory.CreateShape <NullShape>(); shapes[5] = shapeFactory.CreateShape <Circle>(); foreach (var shape in shapes) { shape.Draw(); } Console.WriteLine("Using Non-Generic Method"); IShapeFactory shapeFactoryNonGeneric = new ShapeFactory(); var shapes2 = new IShape[6]; shapes2[0] = shapeFactoryNonGeneric.CreateShape(ShapeType.Circle); shapes2[1] = shapeFactoryNonGeneric.CreateShape(ShapeType.Null); shapes2[2] = shapeFactoryNonGeneric.CreateShape(ShapeType.Rectangle); shapes2[3] = shapeFactoryNonGeneric.CreateShape(ShapeType.Square); shapes2[4] = shapeFactoryNonGeneric.CreateShape(ShapeType.Circle); shapes2[5] = shapeFactoryNonGeneric.CreateShape(ShapeType.Null); foreach (var shape in shapes2) { shape.Draw(); } }