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
What is advantage of code behind coding in ASP.NET?
What is an imagemap in asp.net?
What is http session state?
When using the Pager object, inorder to know which page to go, which property you have to set to grid?
what are the events raised in asp.net page life cycle?in which stage view state can be loaded?
Define view state.
What are the differences between code behind and code inline?
Explain code snippet to register exception filters from controller?
How do I open an ashx file in windows 7?
Is there any property names “isnavigating”?
How is a session stored and maintained in asp.net?
What is bound controls
Suppose You Want A Certain Asp.net Function Executed On Mouseover For A Certain Button. Where Do You Add An Event Handler?
Which Is Faster MVC or ASP.net ?
Is data edited in the Repeater control?