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 are the ihttphandler and ihttphandlerfactory interfaces ?
How to set/get parent page values in child page in asp.net
What is http only cookie?
What is the request flow used for asp.net mvc framework? : asp.net mvc
What is the difference between HTTP-Post and HTTP-Get ?
Which two new properties are added in asp.net 4.0 page class?
What is the difference between asp.net and mvc?
How can we Maintain more than on config file in one .Net web application and how?
Why is xap important?
Where you store Connection string in "Web.Config" file in ASP.NET?
0 Answers Sans Pareil IT Services,
whats the purpose of AUTOPOSTBACK property for the controls in asp.net?
What are Authentication and Authorization?
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)