Skip to content

This repository contains a collection of Java implementations of classic design patterns. Each pattern is demonstrated through clear examples and explanations, aimed at helping developers understand and apply these design principles effectively in their projects.

Notifications You must be signed in to change notification settings

drupalio/DesignPatterns

 
 

Repository files navigation

Design Patterns in Java

Welcome to the Design Patterns repository in Java! This repository contains implementations of various design patterns in Java, aimed at providing clear examples and explanations to help you understand each pattern.

Patterns Included:

Strategy Pattern: This pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable. It lets the algorithm vary independently from the clients that use it .

Observer Pattern: This pattern defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.

Adapter Pattern: is a design pattern that allows incompatible interfaces to work together. It acts as a bridge between two incompatible interfaces by converting the interface of a class into another interface that a client expects. In other words, it allows objects with incompatible interfaces to collaborate.

Composite Pattern: allows you to compose objects into tree structures to represent part-whole hierarchies. It lets clients treat individual objects and compositions of objects uniformly. This pattern is particularly useful when you need to work with objects in a hierarchical manner and you want to treat both individual objects and compositions of objects in a uniform way.

Decorator Pattern: attaches additional responsibilities to an object dynamically. It provides a flexible alternative to subclassing for extending functionality. With this pattern, you can add new features to objects without altering their structure. It involves creating a set of decorator classes that are used to wrap concrete components. Each decorator class adds its own behavior to the component.

Proxy Pattern: creates a surrogate or placeholder for another object, allowing you to control access to it. It acts as an intermediary between the client and the real object, intercepting requests and providing additional functionality such as security checks, logging, or lazy initialization. This pattern enables you to add a layer of indirection to manage access to objects efficiently.

How to Use:

Each pattern implementation is contained within its own folder. Inside each folder, you'll find:

Java source code files (*.java) demonstrating the pattern implementation.

Explanation and usage scenarios in comments within the source code.

UML diagrams illustrating the structure and interactions of classes in the pattern.

To run the code, you'll need a Java development environment set up on your system. Simply compile the Java files and run the main classes to see the pattern in action.

About

This repository contains a collection of Java implementations of classic design patterns. Each pattern is demonstrated through clear examples and explanations, aimed at helping developers understand and apply these design principles effectively in their projects.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%