An open API service indexing awesome lists of open source software.

https://github.com/chandrakanthrck/designpatterns

This Repository contains 8 important design patterns
https://github.com/chandrakanthrck/designpatterns

design-patterns java

Last synced: 3 months ago
JSON representation

This Repository contains 8 important design patterns

Awesome Lists containing this project

README

        

# Design Patterns Implementation

## Overview
This project demonstrates the implementation of common design patterns using **Java**. The patterns covered in this project include **Singleton**, **Factory**, **Abstract Factory**, **Builder**, **Prototype**, **Observer**, **Iterator**, and **Adapter**. These patterns are widely used in software development to create scalable, maintainable, and flexible software systems.

## Design Patterns Implemented

### 1. **Singleton Pattern**
- **Description**: Ensures that a class has only one instance and provides a global point of access to that instance.
- **Use Case**: Useful for managing shared resources like database connections or configuration settings.

### 2. **Factory Pattern**
- **Description**: Provides an interface for creating objects in a superclass but allows subclasses to alter the type of objects that will be created.
- **Use Case**: Useful when the exact types of objects to be created are not known until runtime.

### 3. **Abstract Factory Pattern**
- **Description**: A factory of factories; a factory that creates other factories, allowing the creation of families of related objects without specifying their concrete classes.
- **Use Case**: Ideal when creating multiple objects that are related or dependent on each other.

### 4. **Builder Pattern**
- **Description**: Separates the construction of a complex object from its representation, allowing the same construction process to create different representations.
- **Use Case**: Helpful when constructing complex objects step by step and when the final representation can vary.

### 5. **Prototype Pattern**
- **Description**: Creates new objects by copying an existing object, known as a prototype, rather than creating new instances from scratch.
- **Use Case**: Used when object creation is costly in terms of resources, and you want to avoid the cost of initialization.

### 6. **Observer Pattern**
- **Description**: Defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.
- **Use Case**: Useful in scenarios where changes in one object should trigger updates in dependent objects, like in GUI event systems.

### 7. **Iterator Pattern**
- **Description**: Provides a way to access elements of a collection sequentially without exposing its underlying representation.
- **Use Case**: Commonly used to traverse collections like lists or arrays in a uniform manner.

### 8. **Adapter Pattern**
- **Description**: Allows incompatible interfaces to work together by wrapping an existing class with a new interface.
- **Use Case**: Useful when you need to integrate a class that doesn't match the required interface of a system.

## Project Structure
The project is organized into different packages, each representing a design pattern:

- `design_patterns.singleton`
- `design_patterns.factory`
- `design_patterns.abstract_factory`
- `design_patterns.builder`
- `design_patterns.prototype`
- `design_patterns.observer`
- `design_patterns.iterator`
- `design_patterns.adapter`

Each pattern includes its own set of classes demonstrating how the pattern works.