Skip to content

Latest commit

Β 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧩 System Design & Design Patterns

A collection of practical Java design pattern implementations focused on writing clean, maintainable, scalable, and loosely coupled backend applications.

This repository contains code examples and practical use cases for commonly used Creational, Behavioral, and Structural Design Patterns.


πŸ“š Design Patterns Covered

Pattern Category Purpose
πŸ—οΈ Builder Pattern Creational Build complex objects step-by-step
πŸ”— Chain of Responsibility Behavioral Pass requests through a chain of handlers
πŸ”„ Mapper Pattern Structural / Application Convert objects between different layers/models
🎯 Strategy Pattern Behavioral Select an algorithm/behavior dynamically

πŸ“‚ Repository Structure

System-Design/src/main/java/com/
    |
    +---builder_pattern/
    |       Main.java
    |       PaymentRequest.java
    |       
    +---chain_of_responsibility/
    |   |   ChainConfiguration.java
    |   |   Main.java
    |   |   NotificationRequest.java
    |   |   NotificationService.java
    |   |   
    |   \---handler/
    |           AbstractNotificationHandler.java
    |           EmailHandler.java
    |           NotificationHandler.java
    |           PushHandler.java
    |           SmsHandler.java
    |           
    +---mapper_pattern/
    |       Main.java
    |       RequestMapper.java
    |       TransactionDto.java
    |       
    +---strategy_pattern/
    |   |   Main.java
    |   |   PaymentRequest.java
    |   |   TransactionDto.java
    |   |   
    |   +---request_builder/
    |   |       NeftRequestBuilder.java
    |   |       RequestBuilder.java
    |   |       UpiRequestBuilder.java
    |   |       
    |   \---request_factory/
    |           RequestFactory.java
    |           
    \---system_design
            SystemDesignApplication.java

πŸ—οΈ 1. Builder Pattern

πŸ“Œ What is it?

The Builder Pattern is a creational design pattern used to construct complex objects step-by-step.

It is particularly useful when a class contains:

  • Many fields
  • Optional parameters
  • Multiple combinations of parameters
  • Complex object creation logic

βœ… Advantages

  • Improves code readability
  • Avoids large constructors
  • Supports optional parameters
  • Creates immutable objects
  • Makes object creation easier to understand

🎯 Common Use Cases

DTO creation
Configuration objects
Request objects
Complex domain objects
Immutable objects

πŸ”— 2. Chain of Responsibility Pattern

πŸ“Œ What is it?

The Chain of Responsibility Pattern passes a request through a sequence of handlers.

Each handler can:

  1. Process the request
  2. Reject the request
  3. Pass it to the next handler

🎯 Common Use Cases

Chain of Responsibility is useful for:

  • Request validation
  • Authentication
  • Authorization
  • Logging
  • API filters
  • Payment validation
  • Transaction processing
  • Exception handling

🌱 Spring Boot Example

This pattern can also be seen conceptually in:

HTTP Request
     ↓
Security Filter
     ↓
Authentication Filter
     ↓
Authorization
     ↓
Controller
     ↓
Service

πŸ”„ 3. Mapper Pattern

πŸ“Œ What is it?

The Mapper Pattern is used to convert one object representation into another.

A common backend use case is converting:

Entity ↔ DTO

For example:

Database
   ↓
UserEntity
   ↓
UserMapper
   ↓
UserDTO
   ↓
API Response

🌱 Mapper in Spring Boot

For larger applications, a mapping framework such as MapStruct can reduce repetitive mapping code.

βœ… Advantages

  • Separates DTOs from entities
  • Reduces boilerplate
  • Improves maintainability
  • Prevents exposing database entities directly
  • Makes API contracts cleaner

🎯 Common Use Cases

Entity β†’ DTO
DTO β†’ Entity
Request β†’ Domain Object
Domain Object β†’ Response
External API Model β†’ Internal Model

🎯 4. Strategy Pattern

πŸ“Œ What is it?

The Strategy Pattern allows you to define multiple implementations of an algorithm and select the required implementation dynamically.


🌱 Strategy Pattern in Spring Boot

Spring Boot makes this pattern particularly useful when multiple implementations of the same interface exist.

🎯 Common Use Cases

  • Payment methods
  • Notification channels
  • Authentication mechanisms
  • Pricing strategies
  • Discount calculations
  • File processing
  • Validation strategies
  • API version-specific behavior

βš–οΈ Pattern Comparison

Pattern Category Main Problem Solved
Builder Creational Complex object creation
Chain of Responsibility Behavioral Sequential request processing
Mapper Structural / Application Object transformation
Strategy Behavioral Dynamic behavior selection

🧠 When Should I Use Which Pattern?

Need to create a complex object?
            β”‚
            β–Ό
       Builder Pattern


Need multiple processing steps?
            β”‚
            β–Ό
Chain of Responsibility


Need Entity ↔ DTO conversion?
            β”‚
            β–Ό
       Mapper Pattern


Need different implementations
of the same behavior?
            β”‚
            β–Ό
       Strategy Pattern

πŸš€ Why These Patterns Matter in Backend Development

These patterns are particularly useful when developing Java/Spring Boot microservices.

They help with:

  • ♻️ Code reusability
  • 🧹 Clean code
  • πŸ”Œ Loose coupling
  • πŸ“ˆ Scalability
  • πŸ§ͺ Testability
  • πŸ”§ Maintainability
  • πŸ”„ Extensibility
  • 🧩 Separation of concerns

πŸ› οΈ Technologies

Java Spring Boot Maven Git


πŸ“– References

The examples in this repository are intended for learning and practical backend development.

The implementations can be extended and adapted for real-world applications such as:

Banking Systems
E-Commerce Platforms
Payment Systems
Notification Systems
Video Streaming Platforms
Enterprise Microservices

πŸ‘¨β€πŸ’» Author

Vansh Gala


⭐ If you find this repository useful, consider giving it a star!

Releases

Packages

Contributors

Languages