/// <summary> /// C# Implementation for https://www.tutorialspoint.com/design_pattern/abstract_factory_pattern.htm /// </summary> static void AbstractFactoryPattern() { Console.WriteLine("Start AbstractFactoryPattern"); //get shape factory AFP.AbstractFactory shapeFactory = AFP.FactoryProducer.getFactory("SHAPE"); //get an object of Shape Circle AFP.IShape shape1 = shapeFactory.getShape("CIRCLE"); //call draw method of Shape Circle shape1.draw(); //get an object of Shape Rectangle AFP.IShape shape2 = shapeFactory.getShape("RECTANGLE"); //call draw method of Shape Rectangle shape2.draw(); //get an object of Shape Square AFP.IShape shape3 = shapeFactory.getShape("SQUARE"); //call draw method of Shape Square shape3.draw(); //get color factory AFP.AbstractFactory colorFactory = AFP.FactoryProducer.getFactory("COLOR"); //get an object of Color Red AFP.IColor color1 = colorFactory.getColor("RED"); //call fill method of Red color1.fill(); //get an object of Color Green AFP.IColor color2 = colorFactory.getColor("Green"); //call fill method of Green color2.fill(); //get an object of Color Blue AFP.IColor color3 = colorFactory.getColor("BLUE"); //call fill method of Color Blue color3.fill(); Console.WriteLine("End AbstractFactoryPattern"); }
public Client(AbstractFactory factory) { _productA = factory.CreateProductA(); _productB = factory.CreateProductB(); }