Skip to content

MartinMikes/design-patterns-in-csharp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Design Patterns in C#

A comprehensive guide to design patterns in C#, inspired by the Gang of Four (GoF) book. This repository contains documentation and minimalistic code samples demonstrating each design pattern.

Repository Structure

The patterns are organized into three main categories:

Creational Patterns

Patterns that deal with object creation mechanisms.

  • Singleton - Ensures a class has only one instance
  • Factory Method - Creates objects without specifying exact classes
  • Abstract Factory - Creates families of related objects
  • Builder - Constructs complex objects step by step
  • Prototype - Creates new objects by copying existing ones

Structural Patterns

Patterns that deal with object composition and relationships.

  • Adapter - Allows incompatible interfaces to work together
  • Bridge - Separates abstraction from implementation
  • Composite - Composes objects into tree structures
  • Decorator - Adds behavior to objects dynamically
  • Facade - Provides a simplified interface to a complex system
  • Flyweight - Shares common state between multiple objects
  • Proxy - Provides a surrogate or placeholder for another object

Behavioral Patterns

Patterns that deal with object collaboration and responsibility.

  • Chain of Responsibility - Passes requests along a chain of handlers
  • Command - Encapsulates a request as an object
  • Iterator - Accesses elements of a collection sequentially
  • Mediator - Defines how objects interact
  • Memento - Captures and restores an object's state
  • Observer - Notifies multiple objects about state changes
  • State - Alters object behavior when its state changes
  • Strategy - Defines a family of interchangeable algorithms
  • Template Method - Defines the skeleton of an algorithm
  • Visitor - Separates algorithms from objects they operate on

How to Use

Each pattern directory contains:

  • README.md - Documentation explaining the pattern
  • A minimalistic C# application demonstrating the pattern

Requirements

These samples are built with:

  • .NET 10 - The latest LTS release with enhanced runtime performance
  • C# 14 - Featuring new language improvements including:
    • field keyword for cleaner property implementations
    • Null-conditional assignment (?.=)
    • Extension members and improved Span<T> support
    • Enhanced lambda expressions

To run the samples, install the .NET 10 SDK.

Contributing

Feel free to contribute by adding more examples or improving existing documentation.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages