A professional implementation of the 23 classic Gang of Four (GoF) design patterns in C# 14 with .NET 10.0. This project serves as a practical reference for mid to senior-level software engineers.
Clean, straightforward implementations of all 23 GoF design patterns with:
- Simple, focused examples that demonstrate core concepts
- Professional C# code following modern best practices
- Interactive console application for easy exploration
- No unnecessary complexity - direct and to the point
design-patterns/
├── Infrastructure/
│ ├── IPatternDemo.cs # Pattern interface
│ └── PatternMenuManager.cs # Console menu system
├── Patterns/
│ ├── Creational/ # 5 creational patterns
│ ├── Structural/ # 7 structural patterns
│ └── Behavioral/ # 11 behavioral patterns
└── Program.cs # Application entry point
- .NET 10.0 SDK or later
- Any C# IDE (Visual Studio, VS Code, Rider)
git clone https://github.com/fkucukkara/design-patterns.git
cd design-patterns
dotnet build
dotnet run --project design-patternsThe application provides an interactive menu to explore patterns by category:
- Select a category (Creational, Structural, or Behavioral)
- Choose a specific pattern to see its implementation
- View the demonstration with clear, focused examples
- Factory Method - Payment processor creation system
- Abstract Factory - Cross-platform UI component families
- Builder - Complex database configuration construction
- Prototype - Document template cloning system
- Singleton - Configuration and resource management
- Adapter - Payment gateway integration system
- Bridge - Remote control for different devices
- Composite - File system hierarchy representation
- Decorator - Coffee ordering and text formatting system
- Facade - Home theater system simplification
- Flyweight - Tree forest memory optimization
- Proxy - Image lazy loading system
- Chain of Responsibility - Support ticket handling system
- Command - Smart home automation with undo functionality
- Iterator - Book collection traversal system
- Mediator - Chat room communication system
- Memento - Text editor undo/redo functionality
- Observer - Stock price monitoring and news publishing
- State - Traffic light state transitions
- Strategy - Shipping cost calculation and payment processing
- Template Method - Beverage preparation algorithm
- Visitor - Shape calculation operations
Scenario: Payment processor creation system
- Creates different payment processors (Credit Card, PayPal, Bank Transfer, Crypto)
- Demonstrates object creation without specifying exact classes
- Shows how to handle unsupported payment types gracefully
Scenario: Cross-platform UI component system
- Creates families of related UI components (Windows, macOS, Linux themes)
- Ensures components from the same family work together
- Demonstrates platform-specific implementations
Scenario: Database configuration system
- Constructs complex database configurations step by step
- Provides both traditional builder and fluent interface approaches
- Handles optional parameters and validation
Scenario: Document template system
- Clones document templates for customization
- Demonstrates both shallow and deep cloning approaches
- Uses JSON serialization for reliable deep cloning
Scenario: Configuration and resource management
- Shows thread-safe implementations using
Lazy<T> - Demonstrates practical use cases (logging, caching, configuration)
- Compares different singleton implementation approaches
Scenario: Coffee ordering and text formatting system
- Adds functionality to objects dynamically without altering their structure
- Demonstrates multiple decorators (milk, sugar, caramel, etc.) for coffee customization
- Shows text formatting decorators (bold, italic, underline, color)
- Illustrates flexible composition of features
Scenario: Smart home automation system
- Encapsulates requests as objects for parameterization and queuing
- Demonstrates macro commands that execute multiple actions
- Implements comprehensive undo/redo functionality
- Shows command scheduling and queuing capabilities
Scenario: Stock market monitoring system
- Implements subject-observer relationships for price notifications
- Shows one-to-many dependencies with automatic updates
- Demonstrates category-based subscriptions with news publishing
Scenario: Shipping cost calculation system
- Encapsulates different algorithms for shipping cost calculation
- Allows runtime algorithm selection
- Shows multiple strategy examples (shipping, payment, sorting)
- File-scoped namespaces for cleaner code organization
- Nullable reference types for better null safety
- Pattern matching with switch expressions
- Primary constructors where appropriate
- Record types for immutable data models
- Global using statements for common imports
- Latest performance improvements
- Enhanced nullable annotations
- Improved JSON serialization
- Better async/await patterns
- SOLID principles throughout the codebase
- Dependency injection patterns where applicable
- Exception handling with meaningful error messages
- Documentation with XML comments and examples
- Clean code principles with descriptive naming
- Separation of concerns with proper layering
- Start with Creational Patterns to understand object creation
- Move to Structural Patterns to learn about object composition
- Explore Behavioral Patterns to understand object interaction
- Read the description in the interactive menu
- Run the demonstration to see the pattern in action
- Examine the code to understand the implementation
- Try modifying the examples to test your understanding
- Factory Method - Simplest creational pattern
- Observer - Fundamental behavioral pattern
- Strategy - Commonly used behavioral pattern
- Adapter - Essential structural pattern
- Decorator - Flexible structural pattern
- Command - Powerful behavioral pattern with undo support
- Singleton - Widely used but often misused
- Continue with remaining patterns
# Clean build
dotnet clean
dotnet build
# Run with verbose output
dotnet run --project design-patterns --verbosity detailed
# Build for release
dotnet build --configuration ReleaseThe project follows the coding standards defined in .editorconfig:
- File-scoped namespaces
- 4-space indentation
- PascalCase for public members
- camelCase for private fields
- Comprehensive XML documentation
- Gang of Four Book: "Design Patterns: Elements of Reusable Object-Oriented Software"
- Head First Design Patterns - Excellent for beginners
- Refactoring.Guru - Interactive pattern explanations
- Microsoft Documentation - C# and .NET best practices
This project is licensed under the MIT License. See the LICENSE file for details.