When to Use a Factory Pattern?

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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the use of design patterns?

782


Can we use an equated value as operands for an MVC ? Reason for the same.

2212


What is mvp design pattern?

877


What is the singleton design pattern?

807


Is oop a design pattern?

768


Why have we used synchronized here?

781


Which design pattern is mvc?

806


What are the design patterns you know explain?

840


Explain what is good design?

819


Why should we not use singleton pattern?

768


What is the factory pattern in the design pattern?

914


2. Create your own definition of a system. Based on the “system” definitions a. Identify your viewpoint of shortcomings in the definitions. b. Provide rationale as to why you believe that your definition overcomes those shortcomings. c. From an historical perspective, identify three precedented systems that were replaced by unprecedented systems.

2927


What are useful tools for developing and testing color schemes for web sites?

2233


What is the difference between factory and strategy design pattern?

760


Write the code for a singleton class?

800