design-patterns

Implements SOLID principles and GoF design patterns in C# .NET applications.

Updated Aug 10, 2025
One-click install
npx skills add https://github.com/afonsoft/ai-studio-workspace --skill design-patterns-afonsoft
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: design-patterns
Source: https://github.com/afonsoft/ai-studio-workspace/tree/main/agents/skills/design-patterns
Command: npx skills add https://github.com/afonsoft/ai-studio-workspace --skill design-patterns-afonsoft

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Developers often write tightly coupled, hard-to-maintain .NET code that violates SOLID principles or reinvents solutions to common design problems. This Skill provides concrete C# implementations and refactoring guidance for proven design patterns. ## Core Features & Use Cases - SOLID Refactoring: Before/after C# examples showing how to fix violations of Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion principles. - GoF Pattern Implementations: Ready-to-adapt code for creational patterns (Factory, Abstract Factory, Builder, Singleton), structural patterns (Adapter, Decorator, Facade), and behavioral patterns (Strategy, Observer). - Dependency Injection Integration: Patterns wired with IServiceCollection and constructor injection following standard .NET practices. - Use Case: Given an OrderProcessor class with growing if/else branches for each order type, refactor it using the Open/Closed Principle with an abstract base class and a factory so new order types can be added without modifying existing code. ## Quick Start Refactor this C# class to follow SOLID principles and suggest the appropriate design pattern for my payment processing workflow.

Frequently Asked Questions about design-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I apply SOLID principles in C#?▼

Apply SOLID in C# by separating responsibilities into focused classes, using abstract base classes for extension, designing substitutable hierarchies, creating small focused interfaces, and depending on abstractions injected via constructors. The Skill provides before/after examples for each principle.

How to choose between Factory, Builder, and Abstract Factory patterns?▼

Use Factory Method when a class delegates object creation to subclasses, Abstract Factory when creating families of related objects like platform-specific UI elements, and Builder when constructing complex objects step by step with many optional parameters.

When should I use the Decorator pattern in .NET?▼

Use Decorator when you need to add responsibilities to objects dynamically without subclassing, such as layering logging or SMS delivery onto a notification service. Decorators wrap the same interface and compose at runtime.

Does the Singleton pattern work with dependency injection in .NET?▼

Classic Singleton using Lazy<T> works independently, but in modern .NET you typically register services with AddSingleton in IServiceCollection instead. The Skill shows thread-safe Lazy-based Singleton implementations for cases outside the DI container.

What are the limitations of the Observer pattern in C#?▼

Manual Observer implementations require explicit registration and unregistration to avoid memory leaks, and notification order is not guaranteed. For many .NET scenarios, events, delegates, or IObservable<T> with Reactive Extensions are preferable alternatives.