Design Patterns · Junior · Question 5 of 75

What problem does the Factory pattern solve?

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.

Further reading

Problem with a question

Design Patterns · Junior · question 5

Test yourself

Take the Design Patterns · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz