This repository demonstrates key Software Design Patterns in Java, grouped by category:
- Creational
- Structural
- Behavioral
Each pattern is implemented as an individual, self-contained project with minimal code and maximum clarity — designed for both learning and reference.
design-patterns-java/
├── creational/
│ ├── singleton/
│ │ └── LoggerModule.java
│ ├── builder/
│ │ └── UserModule.java
│ └── abstract-factory/
│ └── UIGenerator.java
├── structural/
│ ├── facade/
│ │ └── HomeTheaterSystem.java
│ └── adapter/
│ └── MusicPlayer.java
└── behavioral/
├── strategy/
│ └── NavigatorModule.java
└── observer/
└── WeatherApplication.java
Ensures a class has only one instance and provides a global point of access to it.
✅ Key Concepts:
- Private constructor
- Static instance
- Thread-safe (with double-checked locking)
Builds complex objects step-by-step without using telescoping constructors.
✅ Key Concepts:
- Immutable object creation
- Chainable setter methods
build()method
Creates families of related objects without specifying concrete classes.
✅ Key Concepts:
- Factory of factories
- Consistency across product families (e.g., Mac UI vs Windows UI)
Provides a simplified interface to a complex subsystem.
✅ Key Concepts:
- Hides complexity
- Single entry point
- Ideal for APIs and libraries
Allows incompatible interfaces to work together.
✅ Key Concepts:
- Converts one interface to another
- Useful for integrating legacy code
Defines a family of algorithms, encapsulates each one, and makes them interchangeable at runtime.
✅ Key Concepts:
- Interface-based design
- Replace logic at runtime
- Promotes flexibility
Defines a one-to-many dependency between objects — when one changes, all dependents are notified.
✅ Key Concepts:
- Publisher-subscriber model
- Real-time notifications
- Loosely coupled components
Each pattern resides in its own folder with a dedicated Main.java. You can:
- Open the folder in your IDE (e.g., IntelliJ, Eclipse)
- Run
Main.java - Observe the output in the console
- Java 17 (or compatible version)
- No external dependencies
- IDE-agnostic folder structure
- Refactoring.Guru
- Design Patterns: Elements of Reusable Object-Oriented Software (GoF)
- Head First Design Patterns
Feel free to fork, modify, and submit pull requests. If you have ideas for additional patterns or examples, contributions are welcome!
This project is licensed under the MIT License.
Dinesh Kumar Gopinathan
⭐ If this helped you understand design patterns better, consider giving it a star!