Skryje voľbu konkrétnej triedy do jedinej vytváracej metódy.
class Transport { deliver(shipment) { throw new Error('abstraktná metóda'); }} class Truck extends Transport { deliver(shipment) { // by road }} class Ship extends Transport { deliver(shipment) { // by sea }} class Drone extends Transport { deliver(shipment) { // by air }} // The only place in the application that names the concrete classes.class TransportFactory { static forRoute(route) { if (route === 'road') return new Truck(); if (route === 'sea') return new Ship(); if (route === 'air') return new Drone(); throw new Error('unknown route: ' + route); }} const a = TransportFactory.forRoute('road');const b = TransportFactory.forRoute('sea');const c = TransportFactory.forRoute('air'); a.deliver(shipment); // the client wrote no new at all