Skip to content

A collection of design patterns implemented in Java, showcasing practical examples of creational, structural, and behavioral patterns.

Notifications You must be signed in to change notification settings

Kahmori/DesignPatterns

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Design Patterns in Java

Introduction

Design patterns are reusable solutions to common problems that occur in software development. They represent best practices evolved over time by experienced developers. Utilizing design patterns helps create systems that are more robust, flexible, and easy to maintain.

This repository contains examples of the following design patterns in Java: Strategy, Builder, Adapter, Singleton, Prototype, Proxy, Factory Method, Chain of Responsibility, and Template Method.

Implemented Patterns

1. Strategy Pattern

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

2. Builder Pattern

The Builder Pattern is used to construct complex objects step by step. It allows you to produce different types and representations of an object using the same construction code.

3. Adapter Pattern

The Adapter Pattern allows objects with incompatible interfaces to work together. It acts as a bridge between two incompatible interfaces, enabling them to communicate and function together.

4. Singleton Pattern

The Singleton Pattern ensures that a class has only one instance and provides a global point of access to that instance. It is useful when exactly one object is needed to coordinate actions across the system.

5. Prototype Pattern

The Prototype Pattern is used to create a duplicate object or clone of the current object to reduce the cost of creating new instances. It allows for the creation of new objects by copying an existing object, known as the prototype.

6. Proxy Pattern

The Proxy Pattern provides a surrogate or placeholder for another object to control access to it. It can add additional functionality, like lazy initialization, access control, logging, etc.

7. Factory Method Pattern

The Factory Method Pattern defines an interface for creating an object but allows subclasses to alter the type of objects that will be created. It lets a class defer instantiation to subclasses.

8. Chain of Responsibility Pattern

The Chain of Responsibility Pattern creates a chain of handler objects, where each handler decides either to process the request or to pass it to the next handler in the chain. It decouples the sender of a request from its receiver.

9. Template Method Pattern

The Template Method Pattern defines the skeleton of an algorithm in the superclass but lets subclasses override specific steps of the algorithm without changing its structure. It allows subclasses to redefine certain steps of an algorithm without changing the algorithm's structure.


For detailed examples and implementation, please refer to the code files in this repository.