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 |
How can I have a particular web page in an asp.net application which displays its own error page?
Should user input data validation occur server-side or client-side? Why?
3 Answers NIC, Siebel Systems,
How do you remove duplicates without using remove duplicate stage?
Explain asp.net application life cycle?
Do ASP.NET forms authentication cookies provide any protection against replay attacks? Do they, for example, include the client's IP address or anything else that would distinguish the real client from an attacker?
Explain Life cycle of ASP.NET page when a request is made.
I am using a range validator and want to use dd mm yyyy format for accepting dates. I get a fairly generic "can't do that" type exception when I use this format for setting the minValue or maxValue properties for the range validator. How can I force it to accept my format?
Dataset is the disconnected environment. suppose if you are binding records to gridview (disconnected environment) and you are making changes to the the grid but before updating the database if any other user modify the data, how will you avoid such problem?
Difference between overriding and overloading?
How to disable cut, copy and paste in TextBox using jQuery in asp.net?
How does the regular expression validator work? What are two situations when you might want to use one?
Explain the difference between or and orelse?