1Z0-804 · Question #153
What are two benefits of a Factory design pattern?
The correct answer is A. Eliminates direct constructor calls in favor of invoking a method E. Prevents tight coupling between your application and a class implementation. Factory methods are static methods that return an instance of the native class. Factory methods : have names, unlike constructors, which can clarify code. do not need to create a new object upon each invocation - objects can be cached and reused, if * can return a subtype of…
Question
What are two benefits of a Factory design pattern?
Options
- AEliminates direct constructor calls in favor of invoking a method
- BProvides a mechanism to monitor objects for changes
- CEliminates the need to overload constructors in a class implementation
- DPrevents the compile from complaining about abstract method signatures
- EPrevents tight coupling between your application and a class implementation
How the community answered
(28 responses)- A86% (24)
- B7% (2)
- C4% (1)
- D4% (1)
Explanation
Factory methods are static methods that return an instance of the native class. Factory methods : * have names, unlike constructors, which can clarify code. * do not need to create a new object upon each invocation - objects can be cached and reused, if * can return a subtype of their return type - in particular, can return an object whose implementation class is unknown to the caller. This is a very valuable and widely used feature in many frameworks which use interfaces as the return type of static factory methods. Note: The factory pattern (also known as the factory method pattern) is a creational design pattern. A factory is a JavaSW class that is used to encapsulate object creation code. A factory class instantiates and returns a particular type of object based on data passed to the factory. The different types of objects that are returned from a factory typically are subclasses of a common The data passed from the calling code to the factory can be passed either when the factory is created or when the method on the factory is called to create an object. This creational method is often called something such as getInstance or getClass .
Topics
Community Discussion
No community discussion yet for this question.