Difference between abstract factory pattern and factory
method pattern in .NET with example.
Answers were Sorted based on User's Feedback
Answer / archanarastogi
The abstract factory pattern provides an interface for
creating a family of objects whereas factory method
provides an interface for creating one object
Is This Answer Correct ? | 39 Yes | 5 No |
Answer / nitin
Abstract factory pattern is used when you do not want the user to change the existing factories, instead allow him to plugin his factory class to create abstract object. Aim is to keep default framework from changing.
Factory method is used when you give the control of the entire framework to user, and he can add new methods to the factory (inorder to create new object type)
Is This Answer Correct ? | 1 Yes | 1 No |
Answer / 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 |
What is difference between cache and session?
What is a user developed application?
When using the Pager object, inorder to know which page to go, which property you have to set to grid?
What is shared and private assembly?
About SOAP ?
33) You create English, French, and German versions of your ASP.NET application. You have separate resource files for each language version. You need to deploy the appropriate resource file based on the language settings of the server. What should you do? A . Create an installer and set the Installer.Context property for each version of your application. B . Create an installer that has a launch condition to verify the locale settings. C . Create an installer that has a custom action to install only location-specific files. D . Create an installer that has an MsiConfigureProduct function to install the appropriate version.
2 Answers Friedkin, ISH, Syntax, Syntax Softtech,
Explain Authentication mechanism in dotnet
Is it possible for me to change my aspx file extension to some other name?
How do you create a permanent cookie?
Define session in asp.net.
What is a page life cycle? What are the events in a page life cycle?
Is web config mandatory?