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 difference between a page theme and a global theme?

546


What is asp.net introduction?

528


What is the difference between response.redirect and server.transfer?

538


where can i gather the materials for MCP certification

4492


What does asp stand for in asp.net?

526






How to prevent client side validation from the ASP.NET validation controls?

579


Which ASP.NET configuration options are supported in the ASP.NET implementation on the shared web hosting platform?

654


What I need to create and run an asp.net application?

516


How to find out what version of asp.net I am using on my machine?

585


What is content place holder?

531


If there are multiple update panels on the page say upd1 and upd2. There is a button placed in upd1. How can you stop upd2 to update when button placed in upd1 is clicked?

573


Difference between web user control and web custom control?

504


Do you know about caching with the datasource controls?

486


What is enableviewstate?

540


Explain the use of errorprovider control in .net?

513