IT lexicon › Programming › Factory pattern

Factory pattern

Programming På svenska → Updated: 2026-05-23

Gang-of-Four creational pattern — move object creation out of the client into a "factory" so the client doesn't need to know concrete classes.

Three flavours: Simple Factory (one static method returns instances), Factory Method (subclasses decide the class), Abstract Factory (families of related objects). Python: __new__ can act as a factory. Spring: Bean Factory.

Sweet spot: when which implementation to create depends on runtime config. Anti-pattern: a factory that just wraps a constructor with no logic = pointless indirection.

← Back to the lexicon