jargon

Design patterns·Making things

one function takes a string and returns the right implementation, and everyone calls it instead of choosing themselves.

Simple factory

Also calledstatic factory, factory helper, parameterised factory

A single place — usually one function with a switch — that maps some input to a concrete class, so the mapping is stated once. It is not in the Gang of Four catalogue and people are sometimes told off for calling it a pattern, but it is by far the most common thing actually written when someone says 'factory'. Reach for it first; the polymorphic factory method is what you graduate to when the switch itself needs to vary.

Commonly confused with