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

What is use case in clean architecture?

622


What is the difference between architecture and design?

589


Why is singleton bad?

577


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

605


What is the difference between factory and builder design pattern?

509






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

2124


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

590


What is the builder pattern?

643


What is the gang of four design pattern?

613


What is clean architecture?

576


Contact a small, medium, and a large contract program within your organization. Interview the Technical Director or Project Engineer to identify the following information: a. Request the individual to graphically depict their development strategy? b. What factors drove them to choose the implementation strategy? c. What were some of the lessons learned from developing and implementing the strategy that would influence their approach next time? d. How was the V & V strategy implemented?

2397


What are the design patterns you know explain?

595


Can we make the reference instance non static?

549


Give me example of observer design pattern?

634


What is the difference between adapter and facade?

633