Design Patterns · Junior · Question 5 of 75
What problem does the Factory pattern solve?
- ✓Correct answer: Creating objects without tying code to their concrete classes
- 2Destroying objects that are no longer used
- 3Copying objects together with all their nested data
Explanation
A createNotification(type) function returns an EmailNotification or a PushNotification, and the calling code works with a common interface. A new type is added in one place. In JS, a factory is often just a function that returns an object.