This repository is a hands-on implementation of SOLID design principles in Java, starting with the Single Responsibility Principle (SRP).
The goal of this project is to build practical, clean examples for all five SOLID principles with simple and understandable code.
SOLID is a set of five object-oriented design principles:
- S – Single Responsibility Principle (SRP)
- O – Open/Closed Principle (OCP)
- L – Liskov Substitution Principle (LSP)
- I – Interface Segregation Principle (ISP)
- D – Dependency Inversion Principle (DIP)
This repository will contain dedicated implementations and examples for each principle.
A class should have only one reason to change.
This example demonstrates SRP using a simple shopping cart system.
designPrinciples/
│
├── src/
│ ├── Main.java
│ └── solidPrinciples/
│ └── srp/
│ ├── Product.java
│ ├── ShoppingCart.java
│ ├── CartRepository.java
│ └── CartInvoicePrinter.java
- Stores product name and price.
- No business logic.
- Adds products.
- Calculates total price.
- Handles cart-related business logic only.
- Responsible for saving cart data.
- Handles persistence only.
- Responsible for printing invoice.
- Handles presentation only.
- Client code to demonstrate usage.
Instead of putting:
- Cart logic
- Database logic
- Printing logic
Inside a single class ❌
We separate them into individual responsibilities ✅
This makes the code:
- Easier to maintain
- Easier to extend
- Easier to test
- Cleaner and scalable
- Open in IntelliJ IDEA (or any Java IDE).
- Configure JDK.
- Run
Main.java.
[DB] Saving 1 items to database.
--- INVOICE ---
GT 650 Chrome : ₹400000.0
TOTAL: ₹400000.0
Structure Verified, SRP
This repository will progressively include:
- Open/Closed Principle (OCP)
- Liskov Substitution Principle (LSP)
- Interface Segregation Principle (ISP)
- Dependency Inversion Principle (DIP)
Each principle will have:
- A bad design example ❌
- A refactored SOLID-compliant version ✅
- Clear explanation
- Strengthen understanding of SOLID principles
- Prepare for Low-Level Design interviews
- Practice writing clean and maintainable code
- Build strong object-oriented fundamentals
This is an evolving repository where all SOLID principles will be implemented step-by-step 🚀
Aspiring Low-Latency Systems Engineer
GitHub | LinkedIn | Blog | Youtube (Just for Updates)