Skip to content

shihabcsedu09/java-design-patterns

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Java Design Patterns

A comprehensive collection of 23 classic design patterns implemented in Java with detailed documentation, examples, and educational resources.

🎯 Overview

This repository serves as a complete learning resource for Java design patterns. Each pattern is:

  • Fully implemented with working code examples
  • Well-documented with detailed explanations
  • Educational with class diagrams and usage examples
  • Production-ready with proper JavaDocs and comments

📚 Implemented Patterns

🏗️ Creational Patterns (5)

Patterns that deal with object creation mechanisms

🏛️ Structural Patterns (7)

Patterns that deal with object composition and relationships

  • Decorator - Add behavior to objects dynamically
  • Adapter - Make incompatible interfaces work together
  • Bridge - Split abstraction from implementation
  • Composite - Treat individual and composite objects uniformly
  • Facade - Provide simplified interface to complex subsystem
  • Flyweight - Share common parts of state between objects
  • Proxy - Provide substitute or placeholder for another object

🎭 Behavioral Patterns (11)

Patterns that deal with communication between objects

  • Chain of Responsibility - Pass requests along handler chain
  • Command - Encapsulate request as object
  • Interpreter - Define grammar representation and interpreter
  • Iterator - Access collection elements without exposing structure
  • Mediator - Reduce coupling between components
  • Memento - Save and restore object state
  • Observer - Notify multiple objects about events
  • State - Alter object behavior when state changes
  • Strategy - Define family of algorithms
  • Template Method - Define algorithm skeleton in method
  • Visitor - Separate algorithms from objects

🚀 Getting Started

Prerequisites

  • Java 8 or higher
  • Maven (for building)

Quick Start

# Clone the repository
git clone https://github.com/shihabcsedu09/java-design-patterns.git

# Navigate to the project
cd java-design-patterns

# Build the project
mvn compile

📖 How to Use

  1. Browse Patterns: Each pattern has its own folder under src/main/java/
  2. Read Documentation: Every pattern includes a detailed README with:
    • Pattern explanation and purpose
    • Implementation details
    • Class diagrams (Mermaid)
    • Usage examples
    • When to use guidance
  3. Run Examples: Each pattern has a main App.java file demonstrating usage
  4. Study Code: Well-commented code with JavaDoc for learning

🎓 Learning Path

Beginner Level

Start with these fundamental patterns:

  1. Singleton - Basic object creation control
  2. Factory Method - Simple object creation
  3. Observer - Event handling
  4. Strategy - Algorithm selection

Intermediate Level

Move to more complex patterns:

  1. Decorator - Dynamic behavior addition
  2. Command - Request encapsulation
  3. State - State-dependent behavior
  4. Template Method - Algorithm structure

Advanced Level

Explore sophisticated patterns:

  1. Visitor - Operation separation
  2. Interpreter - Language interpretation
  3. Mediator - Complex communication
  4. Flyweight - Memory optimization

🛠️ Project Structure

src/main/java/
├── creational/          # Object creation patterns
├── structural/          # Object composition patterns
└── behavioral/          # Communication patterns
    ├── pattern-name/
    │   ├── App.java     # Main demonstration
    │   ├── README.md    # Pattern documentation
    │   └── ...          # Pattern-specific classes

📝 Contributing

We welcome contributions! Here's how you can help:

  1. Report Issues: Found a bug or have a suggestion? Open an issue
  2. Add Patterns: Implement additional design patterns
  3. Improve Documentation: Enhance READMEs or add more examples
  4. Code Quality: Suggest improvements to existing implementations

Contribution Guidelines

  • Follow existing code style and structure
  • Add comprehensive documentation for new patterns
  • Include class diagrams and usage examples
  • Test your implementations thoroughly

📄 License

This project is open source and available under the MIT License.

🙏 Acknowledgments

  • Inspired by the Gang of Four (GoF) design patterns
  • Built for educational purposes and learning
  • Community-driven improvements and feedback

Happy Learning! 🎉

Master the art of software design with these proven patterns.

About

Example codes of common design patterns implemented in java

Resources

License

Stars

1 star

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages