Difference between abstract factory pattern and factory
method pattern in .NET with example.

Answers were Sorted based on User's Feedback



Difference between abstract factory pattern and factory method pattern in .NET with example...

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

Difference between abstract factory pattern and factory method pattern in .NET with example...

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

Difference between abstract factory pattern and factory method pattern in .NET with example...

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

Post New Answer

More ASP.NET Interview Questions

How many types of session in asp.net2.0

28 Answers   ABC, DOT, First Europa, HCL, iRely, TCS,


and can u telme how to explain about our job profile if i have 3years of it experiance in dotnet domain and where to start and where to end , and what shoul i tel and what not(can i mention my education ,and family details,......)i am confusiong a lot. can i ask one with your permision, if u have question that u u went tcs interview as 3+years exp so he/she asked tel me about your profile how can u tel and where to stop. please help me as simple as possible i am facing lot in this..............plese can anyone help me i am awaiting for your reply.

1 Answers   TCS,


Can asp.net work on an nt server?

0 Answers  


What is the T-SQL equivalent of IIF (immediate if/ternary operator) function of other programming languages?

1 Answers   Syntax Softtech,


What r the remotable objects. and how u make an application remotable

1 Answers  






Can I tap into other windows livetm services?

0 Answers  


How Many types of Page Load functions in asp.net

2 Answers  


What is synchronous and Asynchronous post back ?

0 Answers  


can i call the java script to code behind file?if yes how?

4 Answers   Wipro,


How cross page posting is done in Asp.net 2.0?

3 Answers  


What is customer control and user control?

1 Answers   Perot Systems,


how to retrieve property settings from xml .config file.

0 Answers  


Categories