Skapande mönster handlar om objektskapande — hur objekt instansieras, görs flexibla och frikopplas från koden som använder dem. De inkluderar Singleton, Factory, Builder, Prototype och Abstract Factory.
Vad skapande mönster löser
CREATIONAL patterns abstract and control HOW objects are CREATED:
→ instead of directly calling constructors everywhere (rigid, coupled), creational
patterns make object creation flexible, decoupled, and manageable
→ they help create objects in a way suited to the situation, decoupled from concrete classes
De viktigaste skapande mönstren
SINGLETON → ensure only ONE instance of a class (single shared object)
FACTORY METHOD → create objects without specifying the exact class (defer to a method/subclass)
ABSTRACT FACTORY → create FAMILIES of related objects (without specifying concrete classes)
BUILDER → construct complex objects step-by-step (separate construction from representation);
good for objects with many optional parts/parameters
PROTOTYPE → create new objects by CLONING an existing one (copy a prototype)
