Difference between abstract factory pattern and factory
method pattern in .NET with example.

Answer Posted / guest

Abstract Factory patterns acts a super-factory which creates
other factories. This pattern is also called as Factory of
factories. In Abstract Factory pattern an interface is
responsible for creating a set of related objects, or
dependent objects without specifying their concrete classes.

public interface AbstractFactory
{
AbstractProductA CreateProductA();

AbstractProductB CreateProductB();
}

public class ConcreteFactoryA : AbstractFactory
{
public AbstractProductA CreateProductA()
{
return new ProductA1();
}

public AbstractProductB CreateProductB()
{
return new ProductB1();
}
}

public class ConcreteFactoryB : AbstractFactory
{
public AbstractProductA CreateProductA()
{
return new ProductA2();
}

public AbstractProductB CreateProductB()
{
return new ProductB2();
}
}

public interface AbstractProductA { }

public class ProductA1 : AbstractProductA { }

public class ProductA2 : AbstractProductA { }

public interface AbstractProductB { }

public class ProductB1 : AbstractProductB { }

public class ProductB2 : AbstractProductB { }

public class Client
{
private AbstractProductA _productA;
private AbstractProductB _productB;

public Client(AbstractFactory factory)
{
_productA = factory.CreateProductA();
_productB = factory.CreateProductB();
}
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the usie of activex control in .net?

551


Which platform does Microsoft .NET use for exchanging data between applications?

582


Can I have a unique key as foreign key?

538


Why is global asax is used for?

514


What does the hotspot class in .net do?

565






How to find last error which occurred?

532


Which is faster viewbag or viewdata?

556


What are server side controls?

526


What is a ashx file?

550


What is new asp.net core?

571


What will happen if the server confugration file and the application confugration file have different values for sassion state ASP.NET?

745


What are the advantages and limitations of query string?

566


What are the disadvantages of asp.net?

589


Contrast OOP and SOA. What are tenets of each ?

1736


How you can access the values from the Repeater control in ASP.NET?

577