jargon

Design patterns·Making things

the base class does the work and calls a method for the object it needs, and each subclass answers that with a different class.

Factory method

Also calledvirtual constructor, factory method pattern

A method the base class calls to obtain a collaborator, overridden by subclasses to decide which concrete class arrives. It is a single decision point, delegated down the hierarchy — one product, one method — which is exactly what distinguishes it from abstract factory. In modern code the same effect is usually reached by injecting a function or a supplier rather than by subclassing, which is worth saying out loud in an interview.

Commonly confused with