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 skin in asp.net?
How can you implement the postback property of an asp.net control?
Is there any property names “isnavigating”?
Describe how passport authentication works.
Define a static class?
in which protocol ASP.NET WEB API Work?
Can you explain the importance of finalize method in .net?
What is request and response in asp.net?
Can you explain one critical mapping? Performance issue which one is better? Whether connected lookup tranformation or unconnected one?
How can you display all validation messages in one control?
What does occur first in ASP.Net, Authentication or Authorization?
What is the postback property in asp.net?
Does google crawl redirects?
Are xaml file compiled or built on runtime?
How we implement web farm and web garden concept in asp.net?