When to Use a Factory Pattern?

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why do we need singleton pattern?

609


What are the benefits of the proxy in the design pattern?

605


Which design patterns have you used in your project ?

585


Why singleton beans are not thread safe?

593


What are the examples of the behavioral design patterns?

618






What is mvp design pattern?

692


What is the creational design pattern?

640


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

2131


What are the types of participants of the prototype design pattern you will get?

598


Is singleton scope thread safe?

634


Shall we use abstract classes or interfaces in policy / strategy design pattern?

613


Suppose we have file(ps), dont know how many records are there. Move half of the records to 2 files. How can we do?

597


What is the difference between builder and composite?

628


What is the singleton design pattern?

640


What is the difference between factory and builder design pattern?

519