Design Patterns
Essential Creational Patterns
Builder Design Pattern
Factory Design Pattern
Singleton Design Pattern
1. Builder Design Pattern
• The Builder Design Pattern solves the problems of the creation of objects with complex constructors.
• Builder pattern solves the problem of having a big number of possible parameters and unpredictable state by using a method
that will essentially return the eventual Object.
• It separates building a complex object from its representation.
• The process of building an object follows a standard mechanism, allowing the creation of different representations of that
object.
1. Builder Design Pattern
• Builder Design Pattern uses method chaining to builder methods.
• Method chaining uses a series of methods that return the ‘this’ reference for an object.
• The Builder Pattern is commonly used when constructing complex objects, especially those created in phases or requiring
numerous parameters. It's also useful for creating immutable objects.
Example : new Employee. Builder ()
.givenName (“Kazuha")
.surName (“Hajar")
.gender (Gender.FEMALE)
Note that you can also add
.role (Role.STAFF) additional arguments!
.email(“hjr.Eng@example.com")
.build();
2. Factory Design Pattern
• Factory Design pattern helps create objects without exposing the creation logic to the client.
• It centralizes object creation in a dedicated Factory class.
• The Factory Method pattern illustrates a simple way to
produce concrete objects transparently for a client.
• The client obtains a generic Factory reference to a
ConcreteFactory object.
• The ConcreteFactory contains factory methods that
create different objects belonging to the same product
family
3. Singleton Design Pattern
• The Singleton Design Pattern comprises a single class that is responsible for creating only one single object.
Three steps are needed to create a Singleton class:
1. Make the constructor of the singleton class private or protected to prevent direct instantiation from outside the class.
2. Provide the Singleton class with a static reference to hold its single instance.
3. Create a public static method within the Singleton class that returns the single instance of Singleton. The instance can
be created by the getInstance() method or during class creation.
Presenter: Hajar Ait Abdielmomin
Email: hajar.aitabdielmomin@gmail.com
LinkedIn: linkedin.com/in/hajar-ait-abdielmomin-98638421b/
GitHub: github.com/HajarAitAbdielmomin
Medium : medium.com/@hajar.aitabdielmomin
Thank You!
Thank you for your time and attention!
Stay tuned for more deep dives into Software Architecture, Best Practices, and other
exciting topics!