| Lesson 3 | How do creational patterns help programmers? |
| Objective | Explain how Creational Design Patterns are used and provide an example |
Creational Design Patterns address a fundamental challenge in object-oriented software design: how objects are created. Rather than relying on direct constructor calls scattered throughout an application, creational patterns introduce structured techniques that control, abstract, and decouple the object creation process.
This separation is critical in modern systems where flexibility, testability, and long-term maintainability matter more than raw simplicity. By isolating creation logic, applications become easier to extend, refactor, and adapt to new requirements without destabilizing existing code.
At the heart of creational patterns lies abstraction. Instead of binding client code to concrete classes, these patterns allow software to depend on interfaces or abstract classes. The client knows what it needs, not how that need is fulfilled.
Across creational patterns, abstraction enables:
This approach aligns closely with core object-oriented principles, particularly the Open/Closed Principle and the Dependency Inversion Principle.
A widely used real-world example of a creational pattern appears in the Java
standard library. The Factory Method pattern is used to create
network connections through the java.net.URL API.
Rather than forcing programmers to instantiate protocol-specific classes directly, Java exposes a factory method that returns a generalized connection type:
public URLConnection openConnection()
throws IOException
This method returns an instance of URLConnection, which is an
abstract class. Concrete subclasses represent different network
protocols such as HTTP, FTP, SMTP, or others.
Each protocol requires distinct behavior and implementation details. However, client code does not need to be aware of those differences. From the programmer’s perspective, all connections support a consistent interface for reading from and writing to streams.
Because the concrete subclasses are not hard-coded, the system gains several important advantages:
This illustrates a core strength of creational patterns: they allow systems to grow organically as new requirements emerge.
The Gang of Four classifies design patterns into three categories: Creational, Structural, and Behavioral. Creational patterns specifically focus on object instantiation strategies.
The five creational patterns identified are:
Creational patterns are not merely convenience techniques; they encode architectural intent. They reduce fragility in large systems by ensuring that object creation decisions are localized rather than distributed throughout the codebase.
In practice, creational patterns frequently complement structural and behavioral patterns. A Singleton may act as a shared coordinator, while factories supply objects that are later wrapped by decorators or orchestrated by observers.
By adopting creational patterns, developers gain control over who creates an object, how it is created, and when it comes into existence. This control is essential for building scalable, maintainable, and adaptable object-oriented systems.