Skip to content
Back to skills

Design Patterns

ASecurity

Selects and implements a C# design pattern only when it solves a stated variation, construction, or integration problem. Use for Strategy, Factory, Decorator, Adapter, and composition choices; do not force patterns where a simple function is clearer (use csharp-best-practices).

  • 7 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 4, 2026
ai-agentsgoc#testing

Works with

  • cli

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned December 4, 2026

npx -y skills add k4ndev/claude-code-dotnet --skill design-patterns --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Design Patterns?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Design Patterns
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/k4ndev-design-patterns/badge)](https://www.skillsdirectory.com/skills/k4ndev-design-patterns)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: design-patterns
description: Selects and implements a C# design pattern only when it solves a stated variation, construction, or integration problem. Use for Strategy, Factory, Decorator, Adapter, and composition choices; do not force patterns where a simple function is clearer (use csharp-best-practices).
---

# Design Patterns

## Purpose
Choose the smallest design mechanism that makes a real variation or integration boundary explicit without adding unnecessary machinery.

## Scope
Strategy, Factory, Decorator, Adapter, composition, and appropriate built-in .NET/ASP.NET extension points.

## When to use
- The user asks which pattern fits a concrete object creation, algorithm variation, or cross-cutting behavior problem.
- Existing conditional growth or vendor coupling makes the design difficult to change.

## Do not use for
- Pattern catalog/trivia without a project context: explain briefly without creating architecture.
- Project dependency direction: use `clean-architecture`; responsibility design: use `solid-principles`.

## Required context
Know the variation points, callers, object lifetimes, failure behavior, test seams, framework features, and expected number of implementations.

## Workflow
1. Describe the problem without pattern terminology.
2. Compare a function/switch/composition with the requested pattern.
3. Pick Strategy for interchangeable behavior, Factory for genuinely variable/complex construction, Decorator for wrapping a stable contract, Adapter for an external/legacy shape.
4. Check built-in DI, middleware, `DelegatingHandler`, Options, and hosted-service facilities before custom frameworks.
5. Show a focused implementation and explain lifetime/registration; test behavior, selection, and failure paths.

## Decision rules
- Prefer composition for independently varying behavior; do not create a plugin architecture for a fixed pair of cases.
- Use DI to compose known services, not as hidden service location inside domain logic.
- A pattern is justified only if it reduces coupling or clarifies behavior in this scenario.

## Expected output format
State the problem, selected mechanism, why simpler alternatives fail or are sufficient, sample C# code, lifetime considerations, and tests.

## Common mistakes
- Naming a pattern before understanding the problem, over-generalizing factories, wrapping every class in a decorator, or turning a switch into needless polymorphism.

## Edge cases
- A Strategy selected by configuration needs validation and a safe unknown-key path.
- Decorators must preserve cancellation, exceptions, disposal, and result semantics.
- A factory-created `IDisposable` object's ownership must be explicit.

## Examples
See [pattern examples](examples.md) for a payment strategy and a simpler fixed-case alternative.

## Test scenarios
- Positive: “Add two tax calculation policies selected by jurisdiction without growing a giant checkout conditional.”
- Negative: “My process deadlocks under load” routes to `async-concurrency` / `dotnet-diagnostics`.
- Boundary: “Add retry/circuit breaker to `HttpClient`” primarily uses `aspnetcore-patterns` (and resilience guidance if present), not a custom Decorator by default.

## Related skills
`solid-principles`, `clean-architecture`, `aspnetcore-patterns`, `csharp-best-practices`, `testing-quality`.

Files in this skill

  • SKILL.md3.3 KB
  • examples.md1 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.