A comprehensive repository of Design Patterns, SOLID Principles, and System Design implementations in Java. This collection serves as a practical guide for mastering object-oriented design, preparing for technical interviews, and building scalable applications.
- About
- Repository Structure
- SOLID Principles
- Design Patterns
- System Design Projects
- Getting Started
- Contributing
- Resources
This repository provides:
- Practical implementations of 23 Gang of Four design patterns
- SOLID principles with real-world examples
- Complete system designs (Parking Lot, Splitwise, BookMyShow, etc.)
- Interview-ready code with detailed documentation
- Progressive learning path from basics to advanced concepts
Target Audience: Software engineers preparing for interviews, developers learning design patterns, and anyone interested in writing maintainable, scalable code.
Low-Level-Design/
│
├── SOLID Principles/
│ ├── 1. Single Responsibility Principle/
│ ├── 2. Open Closed Principle/
│ └── 3. Liskov Substitution Principle/
│
├── Design Patterns/
│ ├── Creational/
│ │ ├── Factory Design Pattern/
│ │ ├── Prototype Design Pattern/
│ │ └── ...
│ │
│ ├── Structural/
│ │ ├── Adapter Design Pattern/
│ │ ├── Bridge Design Pattern/
│ │ ├── Decorator Design Pattern/
│ │ ├── Facade Design Pattern/
│ │ ├── Flyweight Design Pattern/
│ │ ├── Proxy Design Pattern/
│ │ └── Composite Design Pattern/
│ │
│ └── Behavioral/
│ ├── Observer Design Pattern/
│ ├── Strategy Design Pattern/
│ ├── Command Design Pattern/
│ ├── Chain of Responsibility Pattern/
│ ├── State Design Pattern/
│ ├── Template Design Pattern/
│ ├── Iterator Design Pattern/
│ └── Memento Design Pattern/
│
├── System Design Projects/
│ ├── D1. Docs Design/
│ ├── D2. Parking Lot Design/
│ ├── D3. Instagram Design/
│ ├── D4. Notification Design/
│ ├── D5. Payment Gateway System/
│ ├── D6. Splitwise Design/
│ ├── D7. Dating App/
│ ├── D8. Rate Limiter Design/
│ ├── D9. URL Shortener/
│ ├── D10. Online Ticket Booking System/
│ ├── D11. News Feed System/
│ └── D12. Caching System/
│
├── Real-World Applications/
│ ├── Food Delivery/
│ ├── Search System/
│ └── Subscription System/
│
└── Documentation/
└── Concepts in JS/
Foundational principles for writing clean, maintainable object-oriented code.
Definition: A class should have only one reason to change.
Example: Separating report generation from report printing.
// Bad - Multiple responsibilities
class Report {
void generateReport() { }
void printReport() { }
void saveToDatabase() { }
}
// Good - Single responsibility
class ReportGenerator {
void generateReport() { }
}
class ReportPrinter {
void printReport() { }
}
class ReportRepository {
void saveToDatabase() { }
}Benefits: Easier testing, better maintainability, reduced coupling
Definition: Software entities should be open for extension but closed for modification.
Example: Adding new payment methods without modifying existing code.
interface PaymentProcessor {
void processPayment(double amount);
}
class CreditCardProcessor implements PaymentProcessor {
void processPayment(double amount) { }
}
class UPIProcessor implements PaymentProcessor {
void processPayment(double amount) { }
}
// Add new processor without modifying existing code
class PayPalProcessor implements PaymentProcessor {
void processPayment(double amount) { }
}Benefits: Reduced risk of breaking existing functionality, easier to add features
Definition: Objects of a superclass should be replaceable with objects of subclasses without breaking functionality.
Example: Proper inheritance hierarchy.
// Bad - Violates LSP
class Bird {
void fly() { }
}
class Penguin extends Bird {
void fly() { throw new UnsupportedOperationException(); }
}
// Good - Follows LSP
interface Bird {
void eat();
}
interface FlyingBird extends Bird {
void fly();
}
class Sparrow implements FlyingBird { }
class Penguin implements Bird { }Benefits: Predictable behavior, safer polymorphism
Definition: Clients should not be forced to depend on methods they don't use.
Example: Splitting large interfaces into specific ones.
// Bad - Fat interface
interface Machine {
void print();
void scan();
void fax();
}
// Good - Segregated interfaces
interface Printer {
void print();
}
interface Scanner {
void scan();
}
interface FaxMachine {
void fax();
}
class MultiFunctionPrinter implements Printer, Scanner, FaxMachine { }
class SimplePrinter implements Printer { }Benefits: More flexible implementations, easier to maintain
Definition: Depend on abstractions, not concretions.
Example: Using interfaces for dependencies.
// Bad - Depends on concrete class
class NotificationService {
private EmailSender emailSender = new EmailSender();
}
// Good - Depends on abstraction
interface MessageSender {
void send(String message);
}
class NotificationService {
private MessageSender sender;
NotificationService(MessageSender sender) {
this.sender = sender;
}
}
class EmailSender implements MessageSender { }
class SMSSender implements MessageSender { }Benefits: Loose coupling, easier testing with mocks, flexible implementations
Focus on object creation mechanisms.
| Pattern | Purpose | Use Case |
|---|---|---|
| Factory | Object creation without specifying exact class | Database connections (MySQL, PostgreSQL, MongoDB) |
| Prototype | Clone existing objects | Creating similar game characters |
| Builder | Construct complex objects step-by-step | Building HTTP requests with optional parameters |
| Singleton | Ensure only one instance exists | Logger, Configuration manager |
Deal with object composition and relationships.
| Pattern | Purpose | Use Case |
|---|---|---|
| Adapter | Make incompatible interfaces work together | Integrating legacy payment systems |
| Bridge | Decouple abstraction from implementation | Different vehicles with different engines |
| Decorator | Add responsibilities dynamically | Adding features to coffee orders |
| Facade | Simplified interface to complex subsystem | Home theater system control |
| Flyweight | Share common state to reduce memory | Text editor character rendering |
| Proxy | Control access to another object | Lazy loading images, access control |
| Composite | Treat individual and composite objects uniformly | File system hierarchy |
Focus on communication between objects.
| Pattern | Purpose | Use Case |
|---|---|---|
| Observer | Notify multiple objects of state changes | YouTube channel subscriptions |
| Strategy | Define family of algorithms, choose at runtime | Payment methods, sorting algorithms |
| Command | Encapsulate requests as objects | Text editor undo/redo |
| Chain of Responsibility | Pass request through chain of handlers | Support ticket escalation |
| State | Object changes behavior when state changes | Order status (Pending, Shipped, Delivered) |
| Template Method | Define algorithm skeleton, customize steps | Data processing pipeline |
| Iterator | Sequential access without exposing structure | Iterating through collections |
| Memento | Capture and restore object state | Game save points |
Real-world applications demonstrating multiple patterns working together.
Patterns Used: Observer, Command, Memento
Features: Real-time collaboration, undo/redo, auto-save
Patterns Used: Factory, Strategy, Observer
Features: Multiple vehicle types, dynamic pricing, spot allocation
Patterns Used: Observer, Composite, Strategy
Features: Posts, comments, likes, feed generation
Patterns Used: Strategy, Factory, Template Method
Features: Email, SMS, Push notifications with preferences
Patterns Used: Strategy, Factory, Chain of Responsibility
Features: Multiple payment methods, fraud detection, retries
Patterns Used: Strategy, Observer, Command
Features: Expense splitting algorithms, notifications, settlement
Patterns Used: Strategy, Observer, State
Features: Profile matching, notifications, conversation states
Patterns Used: Strategy, Proxy
Features: Token bucket, sliding window, user/IP-based limits
Patterns Used: Factory, Strategy
Features: Short URL generation, analytics, expiration
Patterns Used: State, Observer, Command
Features: Seat selection, booking flow, notifications
Patterns Used: Observer, Strategy, Composite
Features: Post ranking, personalization, real-time updates
Patterns Used: Proxy, Strategy, Decorator
Features: LRU, LFU, TTL-based eviction policies
- Java 8 or higher
- IDE (IntelliJ IDEA, Eclipse, VS Code)
- Basic understanding of OOP concepts
# Clone the repository
git clone https://github.com/tusquake/Low-Level-Design.git
cd Low-Level-Design
# Navigate to a pattern
cd "Observer Design Pattern"
# Compile
javac *.java
# Run
java MainEach pattern/project folder contains:
Main.java- Runnable exampleREADME.md- Detailed explanation- Supporting classes organized by responsibility
- Start with SOLID Principles
- Learn Creational Patterns (Factory, Singleton)
- Practice Structural Patterns (Adapter, Decorator)
- Master Behavioral Patterns (Observer, Strategy, Command)
- Study pattern combinations
- Implement simple projects (Notification System)
- Complete system designs (Parking Lot, Splitwise)
- Learn when NOT to use patterns
- Practice interview questions
Common combinations seen in production systems:
| Combination | Example | Use Case |
|---|---|---|
| Strategy + Factory + Orchestrator | Search System | Different search algorithms with runtime selection |
| Observer + Command | Text Editor | Undo/redo with UI updates |
| Adapter + Decorator | Food Delivery | Legacy integrations with dynamic features |
| Factory + Singleton + Builder | Email Service | Single manager, provider selection, complex config |
| Chain of Responsibility + Strategy | Authentication | Multiple checks with different auth methods |
Contributions are welcome! Please follow these guidelines:
- Fork the repository
- Create a feature branch (
git checkout -b feature/new-pattern) - Commit your changes (
git commit -m 'Add State pattern example') - Push to the branch (
git push origin feature/new-pattern) - Open a Pull Request
- Add missing design patterns
- Improve documentation
- Add more real-world examples
- Create UML diagrams
- Add unit tests
-
Explain a design pattern you've used in production
- Choose Observer, Strategy, or Factory
- Explain problem, solution, and benefits
-
When would you use Pattern X over Pattern Y?
- Understand tradeoffs
- Provide specific scenarios
-
Design a system using multiple patterns
- Start with requirements
- Identify varying aspects
- Apply appropriate patterns
Author: Tushar Seth
GitHub: @tusquake Linkedin: @Tushar Seth
For questions or suggestions, please open an issue or reach out via GitHub.
Star this repository if you find it helpful for your learning journey!