A comprehensive demonstration of 16 Gang of Four (GoF) Design Patterns implemented in a modern Spring Boot application. This project showcases both traditional pattern implementations and their real-world usage through REST APIs, making it an excellent resource for interviews and learning.
Author: Shivam Srivastav
- ✅ 16 Design Patterns - Complete implementation of Creational, Structural, and Behavioral patterns
- ✅ REST API Layer - Real-world pattern usage via HTTP endpoints
- ✅ Spring AOP Integration - Advanced Proxy pattern demonstration
- ✅ Comprehensive Javadocs - Every class includes detailed documentation with "Why this pattern?" explanations
- ✅ Console Demo - Automatic demonstration on application startup
- ✅ Production-Ready Code - Following Spring Boot best practices
- Singleton:
LoggerService(Spring Bean) - Factory Method:
NotificationFactory - Builder:
Order(Lombok @Builder) - Abstract Factory:
UIFactory(Light/Dark Themes) - Prototype:
Shape(Cloneable)
- Adapter:
PaymentAdapter - Facade:
ShopFacade - Decorator:
UrgentMessageDecorator - Proxy:
DatabaseProxy(and Spring AOPLoggingAspect) - Composite:
Department(Employee Hierarchy)
- Strategy:
CheckoutService(Payment Strategies) - Observer:
EmailNotificationListener(Spring Events) - Template Method:
OrderProcessor - Command:
RemoteControl(Smart Home) - Chain of Responsibility:
SupportHandler - State:
OrderContext(Order Lifecycle)
./mvnw spring-boot:runOn startup, the DesignPatternDemoRunner will execute and print a demonstration of all patterns to the console.
You can interact with the application using the following endpoints to see the patterns in action.
Uses the Builder Pattern to construct the order and the Observer Pattern to notify listeners.
curl -X POST "http://localhost:8080/api/orders?productName=Phone&price=999"Uses the Strategy Pattern to switch between payment methods (PayPal vs Credit Card).
# Pay with PayPal
curl -X POST "http://localhost:8080/api/orders/ORD-123/pay?method=paypal&amount=999"
# Pay with Credit Card
curl -X POST "http://localhost:8080/api/orders/ORD-123/pay?method=card&amount=999"Uses the State Pattern to simulate order lifecycle transitions.
curl "http://localhost:8080/api/orders/ORD-123/status"Uses the Adapter Pattern to process payments via a legacy gateway.
curl -X POST "http://localhost:8080/api/payment/legacy?amount=50"Check the application logs after making any API call. You will see logs from LoggingAspect, demonstrating the Proxy Pattern via Spring AOP.
[INFO] ... [AOP Proxy] Executed ... in 0 ms
