When to Use a Factory Pattern?

Answers were Sorted based on User's Feedback



When to Use a Factory Pattern?..

Answer / guest

A class can?t anticipate which kind of class of objects it
must create.
A class uses its subclasses to specify which objects it creates.
You want to localize the knowledge of which class gets created.


There are several similar variations on the factory pattern
to recognize.
1. The base class is abstract and the pattern must return a
complete working class.
2. The base class contains default methods and is only
subclassed for cases where the default methods are insufficient.
3. Parameters are passed to the factory telling it which of
several class types to return. In this case the classes may
share the same method names but may do something quite
different.

Is This Answer Correct ?    6 Yes 0 No

When to Use a Factory Pattern?..

Answer / md. nasim ahmed

The conventional polymorphism approach can also be used to reach the desired result of handling different class object with same set of methods. But the problem is the driver (main/module) must handle the creation of type of object.
CBase *bptr=new CChild();
bptr->method1();
----
The Factory design pattern ease the programming effort to write the driver program as the creation of object is handled by base class only(factory class).
CBase *bptr= CBase::make_object(chioce);

----
Now refer http://sourcemaking.com/design_patterns/factory_method/cpp/1

Is This Answer Correct ?    4 Yes 0 No

When to Use a Factory Pattern?..

Answer / abhishek kumar

Factory pattern will be used when a creator class works
parallel with the product class

Is This Answer Correct ?    3 Yes 2 No

Post New Answer

More Design Patterns Interview Questions

Explain what is good design?

0 Answers  


What is the use of such a class?

0 Answers  


what are the creational design patterns

0 Answers   Infosys,


What non-visual coding tools are available for web design?

0 Answers   Wipro,


What is Software development life cycle....??

5 Answers   TCS,






Explain what are 5 common problems in the software development process?

0 Answers  


What is clean architecture?

0 Answers  


Hi, I have 9backlogs in btech and i am 2008 passed out,am working with an MNC from past 3 years.now, am willing to do MS, will it be any problem for me?

0 Answers  


What is mvp design pattern?

0 Answers  


What are the biggest trends in UX Design these days?

3 Answers  


What are the design patterns you know explain?

0 Answers  


What are the most popular design patterns?

0 Answers  


Categories