Skip to content

ayoubachak/Design-Patterns

Repository files navigation

Design Patterns

This repository contains Java implementations and explanations of 18 different design patterns. The patterns covered in this repository include:

  • Singleton : This pattern ensures that a class has only one instance and provides a global point of access to that instance.

  • Factory : This pattern provides a way to create objects without specifying the exact class of object that will be created.

  • Observer : This pattern allows objects to be notified of changes to other objects, without those objects being tightly coupled.

  • Decorator : This pattern allows behavior to be added to an individual object, either statically or dynamically, without affecting the behavior of other objects from the same class.

  • Command : This pattern encapsulates a request as an object, which can then be passed to different objects or be queued for later execution.

  • Adapter : This pattern allows incompatible interfaces to work together by providing a wrapper that adapts one interface to match the other.

  • Facade : This pattern provides a simplified interface to a complex system, making it easier to use.

  • Template Method : This pattern defines the skeleton of an algorithm in a method, allowing subclasses to fill in the details.

  • Iterator : This pattern allows iteration over a collection of objects without exposing the underlying representation of the collection.

  • Proxy pattern : This pattern controls access to an object by providing a surrogate.

  • State pattern : which enables an object to change its behavior based on its internal state.

  • Interpreter pattern : which defines a language and provides an interpreter for it.

  • Visitor pattern : which separates an algorithm from an object structure on which it operates.

  • Composite pattern : which composes objects into tree structures to represent part-whole hierarchies.

  • Builder pattern : which separates the construction of a complex object from its representation.

  • Prototype pattern : which creates new objects by copying existing ones.

  • Chain of Responsibility, Mediator which are behavioral patterns that are used to manage communication and dependencies between objects.

  • Abstract Factory : This pattern creates families of related objects without specifying their concrete classes, providing an interface for creating them in different ways.

Each design pattern is presented in its own package, with a detailed explanation of the pattern and a code example that demonstrates how the pattern can be applied in a real-world scenario.

The code is well-organized and easy to follow, making it a great resource for anyone who is learning about design patterns or who is looking for examples of how to implement specific patterns in Java.

Feel free to use this repository as a reference when working on your own projects, or as a learning resource when studying design patterns.

Getting Started

To run the code, you need to have JDK 8 or later installed on your computer. Once you have JDK installed, you can clone this repository to your local machine and open it in your favorite Java IDE.

You can run the code for each design pattern by running the main class for that pattern. The main class is located in the src folder for each package.

Small thing to know, I used junit library to run some tests in some of the Code implementations, I'll upload a zip file containing the libs you need in the libs folder in a future commit.

Contributing

If you find any bugs or have any suggestions for improvements, or some details to add or some grammar to correct in the readme files please feel free to open an issue or submit a pull request.

I did not have enough time to add more design patterns, so feel free to submit a pull request if you think I missed an important one.

Author

This repository was created by Ayoub Achak.

Acknowledgments

I would like to acknowledge the Gang of Four and their book "Design Patterns: Elements of Reusable Object-Oriented Software" as the inspiration for this repository.

About

This repo will contain full examples and tests and explanations on most of the known design patterns

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages