Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Design Patterns Every Developer Should Know: From Principles to Practice
Sep 2, 2025
24 views
Written by Prashant Basnet
👋 Welcome, You’ve Landed on My Signature Page.
I’m a Software Development Engineer passionate about building scalable systems and solving problems.
Beyond engineering, I enjoy sharing ideas and documenting lessons so others can learn and build on them.This space is my digital notebook, a place where I reflect on what I’m learning and creating.
First thing first what's difference between Design Principles vs Design Patterns?
The Why?
Design Principles are broad guidelines or philosophies for writing good software. The nature is that these are very high level, language agnostic & timeless.
Example: SOLID, DRY, KISS, YAGNI.
These are the rules of thumb, like laws of gravity in software design.
The How?
Design patterns on the other had are concrete, reusable solutions to common design problems. These are implementations that you can recognize in the code. Principles are like laws of physics whereas patterns are engineering blueprints built on top of them.
Now let’s walk through the most common patterns, grouped by category.
Design patterns are grouped into 3 categories.
Creational Patterns
1. Singleton Pattern
2. Factory Pattern
Factory will get you the database without knowing how to build it! .
3. Builder Pattern
Problem: Repeated construction of structured responses & request context.
Example:
Benefit: Step-by-step assembly, consistent results, easy to extend.
4. Prototype Pattern
When creating a new object is expensive or complex (e.g., parsing configs, initializing heavy structures), instead of constructing from scratch, you clone an existing prototype.
How it works:
Create a prototype config
Clone for a new service
Here, instead of building configs from scratch every time, you clone the prototype and tweak only what’s different.
Structural Patterns:
5. Adapter Pattern
Problem: A library’s API doesn’t match how your app wants to call it.
Example: AuthProvider adapter wrapping an external auth SDK.
Now the rest of your app always calls the clean interface:
Benefit: One consistent interface; swap libraries with minimal changes.
6. Decorator Pattern
In software design, the Decorator pattern is a structural pattern that:
You have a plain coffee (the base object).
7. Composite Pattern
It lets you treat a group of objects the same way as a single object.
The composite wraps multiple child objects and forwards calls to them.
Example
You have multiple metrics writers:
Normally, you’d have to call each one separately:
But with a Composite:
You treat many writers as if they were one writer.
Benefit: Uniform interface; adding a new metrics sink is zero-effort.
8. Facade Pattern
Example (Payments Facade):
✅ Benefit: Simplifies usage for clients while keeping subsystems separate.
9. Strategy Pattern:
You need to get to work, but you can choose different strategies:
one way to do it is without Strategy Pattern, messy if else everywhere
✅ With Strategy Pattern - Clean & Flexible
// Add new strategy without changing existing code!
💡 Key Points:
Behavioral Patterns
10. Observer Pattern
A behavioral design pattern where an subject maintains a list of dependents observers and notifies them automatically of any state changes. The Observer pattern is about one to many communication.
Observers (subscribers) handle these events:
When the route completes, the bus notifies all observers at once.
11. Command Pattern
It's a behavioral design pattern. It wraps an action like method call into an object so that we can treat it like data. So that we can :
Instead of calling service.doSomething(), you wrap it as a Command and run it through a standard pipeline.
Command turns an action into a standard object (or function) so you can execute it consistently with extra behavior (logging, error handling, retries).
Benefit: Standardized execution pipeline
These are the most common design patterns.