/design-patterns-and-principles

A collection of popular design patterns implemented in Java. This repository provides code examples and explanations of creational, concurrency, structural, and behavioral patterns, helping developers understand and apply design patterns in real-world scenarios.

Primary LanguageJavaMIT LicenseMIT

License People Stars Forks Watches Last Updated

Description

Welcome to the Design Patterns and Principles Repository! This repository serves as a comprehensive collection of widely used design patterns and principles in software development, demonstrating best practices in software architecture and engineering. It aims to provide a practical guide to understanding and applying both patterns and principles to solve common challenges, creating flexible, reusable, and maintainable systems.

Installation

Instructions on how to set up the project on a local machine:

  1. Clone the repository:

    git clone git@github.com:TheCollinsByte/design-patterns-and-principles.git
  2. Navigate to the project directory:

    cd design-patterns-and-principles
  3. Ensure you have JDK version 21 installed. You can download it here.

  4. Compile the project:

    ./gradlew build
  5. Run the project:

    ./gradlew :{MODULE_NAME}:test -Dtest.verbose=true

Design Patterns

This repository includes examples of commonly used design patterns, each with detailed explanations and code implementations. Design patterns are proven solutions to recurring problems in software design and are categorized here by their purpose:

Creational Patterns

  • Abstract Factory
  • Builder
  • Factory Method
  • Prototype
  • Singleton

Structural Patterns

  • Adapter
  • Bridge
  • Composite
  • Decorator
  • Facade
  • Flyweight
  • Proxy

Behavioral Patterns

  • Chain of Responsibility
  • Command
  • Interpreter
  • Iterator
  • Mediator
  • Memento
  • Observer
  • State
  • Strategy
  • Template Method
  • Visitor

Concurrency Patterns

  • Thread Pool
  • Executor
  • Producer-Consumer
  • Reactor

Design Principles

This section covers fundamental design principles, such as SOLID, that guide software development and promote robust, maintainable, and scalable code. Each principle includes explanations, examples, and best practices.

SOLID Principles

The SOLID principles represent core guidelines for object-oriented design:

  1. Single Responsibility Principle (SRP): A class should have only one reason to change, meaning it should only have one job or responsibility.
  2. Open/Closed Principle (OCP): Software entities (classes, modules, functions) should be open for extension but closed for modification.
  3. Liskov Substitution Principle (LSP): Subtypes should be substitutable for their base types without altering the correctness of the program.
  4. Interface Segregation Principle (ISP): Clients should not be forced to depend on interfaces they do not use. Split interfaces into smaller, specific ones.
  5. Dependency Inversion Principle (DIP): High-level modules should not depend on low-level modules; both should depend on abstractions.

Each principle has its dedicated folder within the repository containing code samples and documentation.

Contributing

Contributions are Welcome! Please follow these steps:

  1. Fork the repository.
  2. Create a new branch (git checkout -b name-dp-module)
  3. Make your changes and commit them (git commit -m "Design Pattern/Principle: ...")
  4. Push to the branch (git push origin name-dp-module).
  5. Create a new Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.



⭐ Hit the star button if you found this useful ⭐

Source | Twitter | LinkedIn | Email