Comparison
Abstract factoryvsFactory method
Abstract factory
you swap one object at startup and the whole family of things it creates changes together, consistently.
An interface that creates a family of related products, with one implementation per family, so the products cannot be mismatched. The point is consistency across several types at once — a widget set where the scrollbar and the button must come from the same theme — rather than the single choice a factory method makes. It is heavily over-applied: with one family it is a class hierarchy that exists to hold one `new`.
Full entry →Factory method
the base class does the work and calls a method for the object it needs, and each subclass answers that with a different class.
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.
Full entry →