public static void Main()
AbstractFactory sp = FactoryProducer.getFactory("shape");
IShape circle = sp.getShape("circle");
IShape triangle = sp.getShape("triangle");
AbstractFactory col = FactoryProducer.getFactory("color");
col.getColor("red").fill();
col.getColor("yellow").fill();
public class Circle: IShape{
Console.WriteLine("From Circle");
public class Triangle: IShape{
Console.WriteLine("From Triangle");
public class Red: IColor{
Console.WriteLine("RED Color");
public class Yellow: IColor{
Console.WriteLine("Yellow Color");
public abstract class AbstractFactory{
public abstract IShape getShape(string shapename);
public abstract IColor getColor(string colrname);
public class ShapeFactory : AbstractFactory {
public override IShape getShape(string shapeType){
if (shapeType.ToLower() == "circle"){
else if (shapeType.ToLower() == "triangle"){
public override IColor getColor(string colrname){
public class ColorFactory : AbstractFactory{
public override IColor getColor(string shapeType){
if (shapeType.ToLower() == "red"){
else if (shapeType.ToLower() == "yellow"){
public override IShape getShape(string shapeType){
public class FactoryProducer{
public static AbstractFactory getFactory(string type){
return new ShapeFactory();
else if (type == "color"){
return new ColorFactory();