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
The 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
Each pattern implementation includes:
- Core pattern structure
- Simple, practical example
- Clean, readable code
- Professional implementation approach
- .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 run --project design-patterns- Factory Method - Payment processor creation
- Abstract Factory - Cross-platform UI components
- Builder - Database configuration builder
- Prototype - Document template cloning
- Singleton - Configuration manager
- Adapter - Legacy system integration
- Bridge - Device abstraction
- Composite - File system hierarchy
- Decorator - Feature enhancement
- Facade - System simplification
- Flyweight - Memory optimization
- Proxy - Lazy loading
- Chain of Responsibility - Request handling
- Command - Action encapsulation
- Iterator - Collection traversal
- Mediator - Object communication
- Memento - State preservation
- Observer - Event notification
- State - State-dependent behavior
- Strategy - Algorithm selection
- Template Method - Algorithm skeleton
- Visitor - Operation separation
cd design-patterns
-
Build the project:
dotnet build
-
Run the application:
dotnet run --project design-patterns
-
Navigate the interactive menu to explore different patterns:
- Choose pattern categories (Creational, Structural, Behavioral)
- Select specific patterns to see live demonstrations
- Follow along with the console output to understand each pattern
- 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.