Design Making Patterns
Design Making Patterns
It is a creational design pattern that ensures a class has only one instance and provides a global
access point to that instance.
Key Characteristics:
1. Single Instance: Only one object of the class can exist.
2. Global Access: That instance is accessible globally through a static method.
3. Controlled Instantiation: The class controls how and when the instance is created.
● You need exactly one instance of a class to coordinate actions across the system.
Pros:
Cons:
Used to separate the construction of a complex object from its representation, so the same
construction process can create different representations.
Key Components:
1. Builder: An abstract interface or base class that defines the steps to build the object.
2. ConcreteBuilder: Implements the steps defined in the Builder to construct and
assemble the parts.
3. Director (optional): Orchestrates the building process using the builder.
Benefits:
● More readable and maintainable code when dealing with many optional parameters.
Drawbacks:
It is used To encapsulate object creation logic so that the client code doesn’t need to know the
exact class of the object it is creating.
Key Idea:
Instead of instantiating objects directly using new, you delegate the creation to a factory method.
When to Use:
● When the exact type of the object isn’t known until runtime.
● When you need to return objects from a common base class or interface.
Advantages:
Disadvantages:
● Doesn’t eliminate the need for new, just moves it to a centralized place.