Chapter 3: Creational Design Patterns
Loading audio…
ⓘ This audio and summary are simplified educational interpretations and are not a substitute for the original text.
Creational Design Patterns patterns achieve flexibility by encapsulating knowledge about which concrete classes are utilized and hiding the mechanics of instance creation, allowing for configuration that can be static or dynamic. The sources introduce five key creational patterns. The Abstract Factory pattern (also known as Kit) establishes an interface for creating entire families of related product objects, ensuring they are used together consistently, such as using a WidgetFactory to ensure all user interface elements adhere to a specific look and feel like Motif or Presentation Manager. The Builder pattern separates the construction steps of a complex product from its ultimate representation, allowing the same construction process, often dictated by a Director object (like an RTFReader parser), to generate varying output formats (Products) via different Concrete Builders (like ASCII or TeX converters). The Prototype pattern relies on specifying new objects by copying or "cloning" existing prototypical instances. This approach drastically reduces the need for creating a factory class hierarchy parallel to the product hierarchy, allowing for dynamic system configuration and specification of new objects simply by altering the prototype's internal state values. The Factory Method pattern (known as Virtual Constructor) is a class creational pattern where a Creator class declares a method for object creation but defers the actual instantiation decision to its subclasses, which implement the method to return the appropriate concrete product. This is commonly used in frameworks, like the Application and Document examples, to provide subclasses with customization hooks for object generation. Lastly, the Singleton pattern guarantees that a class has only one instance and provides a globally recognized, controlled access point to that sole instance, avoiding the uncontrolled access and name space pollution associated with global variables. The patterns are illustrated using the persistent example of building components (Rooms, Walls, Doors) for a computer maze game, highlighting how each pattern can introduce flexibility into a formerly hard-coded construction routine.