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

Which ASP.NET configuration options are supported in the ASP.NET implementation on the shared web hosting platform?

0 Answers  


Explain the advantages of asp.net.

0 Answers  


What is the difference between WindowsDefaultLocation and WindowsDefaultBounds?

0 Answers   BirlaSoft,


how we declare interface

2 Answers  


What are Http handler ?

1 Answers   Patni,


Rate yourself in .net and sql database?

1 Answers   BrickRed, Infosys, Satyam, SP Software,


What is the difference between a Thread and Process?

1 Answers  


For a server control, you need to have same properties like color maxlength, size, and allowed character throughout the application. How do you handle this?

2 Answers   Microsoft,


Which color scheme in a Repeater control can you provide alternatively?

1 Answers   Siebel,


Take one textbox if I am inputting abc alphabet in capital letter or in small letter on the button click it will be bcd or if I enter 123 and it would be 234 like that in ASP.NET?

3 Answers   DNS,


How is session id generated?

0 Answers  


how can we maintain security in soted procedure?

1 Answers  


Categories