Which statement describes the Factory design pattern?

Prepare for the FAST Enterprises IC Interview. Enhance your skills with flashcards and multiple-choice questions. Each question provides hints and detailed explanations. Excel in your interview!

Multiple Choice

Which statement describes the Factory design pattern?

Explanation:
Centralizing object creation so the caller doesn’t know the exact class being instantiated is the essence of the Factory pattern. A factory method takes input (for example, 'CIRCLE') and returns an instance that implements a common interface, with the concrete type chosen inside the factory. This is exactly what ShapeFactory.create('CIRCLE') demonstrates, returning a Circle instance behind the scenes. The benefit is decoupling the code that uses the objects from the code that creates them; if you add new shapes or switch implementations, you can do so without changing client code. It also makes it easier to manage complex creation logic in one place. The other descriptions describe different patterns: one concerns selecting among interchangeable algorithms (Strategy), another is about passing a request along a chain of handlers (Chain of Responsibility), and another ensures only a single instance of a class exists (Singleton).

Centralizing object creation so the caller doesn’t know the exact class being instantiated is the essence of the Factory pattern. A factory method takes input (for example, 'CIRCLE') and returns an instance that implements a common interface, with the concrete type chosen inside the factory. This is exactly what ShapeFactory.create('CIRCLE') demonstrates, returning a Circle instance behind the scenes. The benefit is decoupling the code that uses the objects from the code that creates them; if you add new shapes or switch implementations, you can do so without changing client code. It also makes it easier to manage complex creation logic in one place. The other descriptions describe different patterns: one concerns selecting among interchangeable algorithms (Strategy), another is about passing a request along a chain of handlers (Chain of Responsibility), and another ensures only a single instance of a class exists (Singleton).

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy