- A Class should have only one reason to change.
- Focused single Responsibility addresses a specific concern.
- If you can’t describe what a class does in one clear sentence without using "and", it’s probably doing too much.

- A class, module, or function should be open for extension but closed for modification.
- Open for extension → You should be able to add new functionality.
- Closed for modification → You should NOT change the existing code whenever a new requirement comes.

- Objects of a superclass should be replaceable with objects of its subclasses without breaking the application.
- Subclass should extend the capability of the parent class but not narrow it down.
- ✅ Example: Bird bird = new Sparrow(); → works fine, since Sparrow behaves like a Bird.
- ❌ Violation: Bird bird = new Penguin(); → breaks, since Penguin can’t fly but the parent expects fly().

- Interface should be such that the client should not implement unneccessary functions they do not need.
- Don’t force someone to depend on methods they don’t use.
- Keep interfaces small and focused, so classes only worry about what they actually do.
- High-level modules should not depend on low-level modules.
- Both should depend on abstractions.
- Abstractions should not depend on details.
- Details should depend on abstractions.
-
In simple terms: If high-level logic directly depends on low-level implementations, changes in the low-level code can break the high-level logic.
-
In more simple terms: Class should depend on interface rather than concrete class.

-
Simple Factory : A design pattern that delegates object creation to a single factory class, keeping your code clean and reducing coupling.
-
Centralizes object creation
-
Reduces repetitive new calls
-
Keeps client code clean
-
Perfect when you often switch between related object types
-
Factory Method: Defines an interface for creating an object.
-
Lets subclasses decide which class to instantiate
-
Decouples object creation from usage
-
Keeps client code clean
-
You order something, but you don’t know exactly which concrete object will be created.
-
Abstract Factory is a creational design pattern
-
It provides an interface to create families of related objects
-
The client does not know or care about concrete implementations
-
Object creation logic is fully encapsulated
* Standard Definiation: Separate the construction of a complex object from its representation, so that the same construction process can create different representations.* Every new optional param requires a new constructor overload. * Calls become uncreachable as you pass empty/dummy values for skipped field.* partially build objects may be used before all required data is set.* Exposing setters means client can change the object any time.Problems it solves: ❌ Constructors with too many parameters ❌ Confusing parameter order ❌ Poor readability ❌ Hard to extend when new fields are added Benefits: ✅ Readable and fluent object creation ✅ Immutable objects ✅ Better control over object creation ✅ Same construction logic → different outputsA Simple Builder (also called Fluent Builder) is a creational pattern where a single builder class constructs an object step by step using method chaining, and the client directly calls build() to create the final object.* Usually implemented as a static inner class * Uses fluent API (method chaining) * No Director class * All construction logic is inside the Builder* Object has many optional parameters * You want readable object creation * You want immutable objects
A Director Builder is the classic implementation described by the Gang of Four,
where a separate Director class controls the construction process, and different
Concrete Builders create different representations of the product using the same building steps.
* Separate Builder interface
* Multiple Concrete Builders
* A Director orchestrates build steps
* Same construction process → different outputs
* Construction process must be reusable
* Different representations of the same object are needed
* Complex creation workflows
A Step Builder is a variation of the Builder pattern that enforces the order of method calls
at compile time using multiple interfaces, ensuring that
mandatory fields are set before the object can be built.
-> Enforces mandatory fields
-> Provides compile-time safety
-> Allows optional fields at the end
-> Prevents incomplete object creation
-> Strict creation workflow required
-> Certain fields are mandatory
-> You want compile-time safety
The Prototype Pattern is a creational design pattern where new objects are created by copying (cloning)
an existing object instead of creating from scratch using new.
Use it when:
* Object creation is expensive
* Object has many configuration fields
* You want to avoid complex constructor logic
* You want to create objects at runtime dynamically
The Singleton Pattern ensures that a class has only one instance and provides a global access point to it.
✅ Controls resource usage (e.g., DB connection, Logger, Config)
✅ Prevents unnecessary object creation
✅ Ensures consistency across the application
There are various ways we can implement singleton design pattern
- Eager Initialization
- Lazy Initialization – NOT Thread Safe
- Lazy Initialization – Double-Checked Locking - Thread Safe
- Lazy Initialization – Bill pugh
- Enum Singleton








