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
Contrast oop and soa. What are tenets of each16. How does the xmlserializer work? What acl permissions does a process using it require?
What is the displayafter property in updateprogress control?
What is difference between asp.net and asp?
What is the namespace to create thread in .net?
Explain managed code an un-managed code.
What permissions do asp.net applications posses by default?
Can we have multiple web config files for an asp.net application?
Why is string called immutable data type?
Explain how cookies work. Give an example of cookie abuse.
What are the different types of validation controls in asp.net?
What is odata in web api?
Can I tap into other windows livetm services?
What is the difference between debug and release?
How can you handle errors in Web API?
Who can consume WebAPI?