Skip to content

23 Gang of Four Design Patterns in C# This repository contains implementations of the 23 Gang of Four (GoF) Design Patterns in C#. Each pattern is demonstrated with real-time examples to help understand its usage and application in software design.

Notifications You must be signed in to change notification settings

sandeeppaldotnet/Complete-23-Gang-of-Four-Design-Patterns-in-C-With-Real-Time-Examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Complete-23-Gang-of-Four-Design-Patterns-in-C-With-Real-Time-Examples

Complete 23 Gang of Four Design Patterns in C# With Real-Time Examples

23 Gang of Four Design Patterns in C#

This repository contains implementations of the 23 Gang of Four (GoF) Design Patterns in C#. Each pattern is demonstrated with real-time examples to help understand its usage and application in software design.

Table of Contents

Introduction

Design patterns are proven solutions to common software design problems. They provide a template for how to solve issues in software architecture, making your code more flexible, reusable, and easier to maintain.

Design Patterns

Creational Patterns

  1. Singleton

    • Ensures a class has only one instance and provides a global point of access.
    • Example: Configuration settings manager.
  2. Factory Method

    • Defines an interface for creating an object but allows subclasses to alter the type of created objects.
    • Example: Shape factory for different shapes (Circle, Square).
  3. Abstract Factory

    • Provides an interface for creating families of related or dependent objects without specifying their concrete classes.
    • Example: UI widget factory (Windows, Mac).
  4. Builder

    • Separates the construction of a complex object from its representation.
    • Example: MealBuilder for creating complex meal objects.
  5. Prototype

    • Creates new objects by copying an existing object, known as the prototype.
    • Example: Cloning a game character.

Structural Patterns

  1. Adapter

    • Allows incompatible interfaces to work together.
    • Example: Adapter for integrating a new payment gateway with an existing system.
  2. Bridge

    • Decouples an abstraction from its implementation so that the two can vary independently.
    • Example: Remote control for different types of devices.
  3. Composite

    • Composes objects into tree structures to represent part-whole hierarchies.
    • Example: Graphic design elements (Shapes, Groups).
  4. Decorator

    • Adds new functionality to an object dynamically.
    • Example: Adding features to a coffee order (milk, sugar).
  5. Facade

    • Provides a simplified interface to a complex subsystem.
    • Example: A simplified API for a library with multiple classes.
  6. Flyweight

    • Reduces memory usage by sharing common parts of state between multiple objects.
    • Example: Character representation in a text editor.
  7. Proxy

    • Provides a surrogate or placeholder for another object to control access.
    • Example: Virtual proxy for loading images.

Behavioral Patterns

  1. Chain of Responsibility

    • Passes a request along a chain of handlers.
    • Example: Logging framework with multiple log levels.
  2. Command

    • Encapsulates a request as an object, thereby allowing for parameterization of clients.
    • Example: GUI buttons that execute commands.
  3. Interpreter

    • Defines a representation for a language's grammar and provides an interpreter to use it.
    • Example: Simple expression evaluator.
  4. Iterator

    • Provides a way to access elements of a collection sequentially without exposing its underlying representation.
    • Example: Custom collection of books.
  5. Mediator

    • Defines an object that encapsulates how a set of objects interact.
    • Example: Chat room where users communicate.
  6. Memento

    • Captures and externalizes an object's internal state without violating encapsulation.
    • Example: Undo functionality in a text editor.
  7. Observer

    • Defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified.
    • Example: News subscription service.
  8. State

    • Allows an object to alter its behavior when its internal state changes.
    • Example: Vending machine states.
  9. Strategy

    • Defines a family of algorithms, encapsulates each one, and makes them interchangeable.
    • Example: Sorting algorithms for different data types.
  10. Template Method

    • Defines the skeleton of an algorithm in a method, deferring some steps to subclasses.
    • Example: Game development (initializing levels).
  11. Visitor

    • Represents an operation to be performed on elements of an object structure.
    • Example: File system operations (copy, delete).

Real-Time Examples

For each design pattern, there is a dedicated folder containing:

  • The pattern implementation in C#
  • A detailed explanation
  • Example use cases

About

23 Gang of Four Design Patterns in C# This repository contains implementations of the 23 Gang of Four (GoF) Design Patterns in C#. Each pattern is demonstrated with real-time examples to help understand its usage and application in software design.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages