Welcome to the Design Patterns Repository, a comprehensive collection of design pattern implementations in Java. This repository serves as a learning resource for developers aiming to understand and apply design patterns effectively in real-world projects.
Design patterns are essential in software development, providing reusable solutions to common problems. This repository is structured to demonstrate various creational, structural, and behavioral design patterns with well-documented Java implementations.
The repository is organized by design pattern categories:
Design Patterns/ ├── src/ │ ├── creational/ │ │ ├── singleton/ │ │ │ ├── thread_safe/ │ │ │ │ ├── Logger.java │ │ │ │ ├── TicketReservation.java │ │ │ │ └── User.java │ │ │ └── ... (other singleton implementations) │ │ ├── factory/ │ │ │ └── ... │ │ └── ... (other creational patterns) │ ├── structural/ │ │ ├── adapter/ │ │ │ └── ... │ │ ├── decorator/ │ │ │ └── ... │ │ └── ... (other structural patterns) │ ├── behavioral/ │ │ ├── observer/ │ │ │ └── ... │ │ ├── strategy/ │ │ │ └── ... │ │ └── ... (other behavioral patterns) │ └── Main.java ├── .gitignore └── README.md Each category contains subdirectories for individual patterns, where you’ll find Java source code along with necessary documentation.
Patterns that focus on efficient object creation.
-
Singleton
- Implemented a thread-safe Singleton Logger using double-checked locking.
- Demonstrated usage through a multithreaded Ticket Reservation system.
-
Factory Method (To be added)
-
Abstract Factory (To be added)
-
Builder (To be added)
-
Prototype (To be added)
Patterns that deal with class and object composition.
- Adapter (To be added)
- Decorator (To be added)
- Facade (To be added)
- Proxy (To be added)
Patterns that focus on communication between objects.
- Observer (To be added)
- Strategy (To be added)
- Command (To be added)
- State (To be added)
git clone <repository_url>cd Design-PatternsUsing an IDE (IntelliJ IDEA, Eclipse, etc.):
- Import the project as a Maven/Gradle project.
- Run
Main.javaor specific pattern implementations.
Using the Command Line:
-
Compile Java files:
javac -d out src/**/*.java
-
Run the main class:
java -cp out Main
Browse the src directory to find implementations for various design patterns.
Contributions are welcome! To contribute:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Commit your changes with a meaningful message.
- Push your branch to your forked repository.
- Submit a Pull Request for review.
-
Follow the Google Java Style Guide.
-
Maintain clean and well-documented code.
-
Write unit tests wherever applicable.
-
Use meaningful variable and method names.
-
Commit messages should follow the format:
<type>[optional scope]: <description>