strategy-pattern

Encapsulate interchangeable algorithms behind a common interface in TypeScript and Rust.

Updated Apr 10, 2026
One-click install
npx skills add https://github.com/erichugy/agentic.skills --skill strategy-pattern
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: strategy-pattern
Source: https://github.com/erichugy/agentic.skills/tree/main/strategy-pattern
Command: npx skills add https://github.com/erichugy/agentic.skills --skill strategy-pattern

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Encapsulates a family of algorithms behind a common interface to eliminate growing switch or if/else chains and make behavior pluggable at runtime.

Core Features & Use Cases

  • Swappable Algorithms: Define interchangeable strategies that can be selected or registered at runtime to change behavior without modifying existing code.
  • Language Examples: Includes patterns and guidance for both TypeScript (function- and class-based strategies) and Rust (traits and implementations).
  • Practical Uses: Useful for export formatting, pricing strategies, compression selection, authentication modes, and any case where runtime behavior should be extensible.

Quick Start

Use the strategy-pattern skill to replace a type-based switch with a registry of strategy implementations and select the appropriate strategy at runtime.

Frequently Asked Questions about strategy-pattern

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

FAQPage Schema
How do I replace growing switch or if/else chains with swappable algorithms in TypeScript?

To replace switch or if/else chains with swappable algorithms, define a common strategy interface, implement multiple concrete strategy classes, and select the desired algorithm at runtime. This refactoring encapsulates behavior, making it pluggable without modifying existing code.

What is the strategy pattern and when should I use it for runtime behavior selection?

The strategy pattern encapsulates a family of interchangeable algorithms behind a common interface. Use it for runtime behavior selection when you need to swap logic dynamically, such as changing export formats, pricing strategies, or compression selection without altering client code.

Does the strategy pattern work with both TypeScript and Rust for algorithm selection?

Yes, the strategy pattern works with both TypeScript and Rust. In TypeScript, you can use function-based or class-based strategies implementing a shared interface. In Rust, you define a strategy trait and implement it for multiple concrete structs to achieve runtime algorithm selection.

How do I implement a strategy registry for runtime selection in Rust?

Implement a strategy registry in Rust by defining a trait for your algorithms, creating concrete implementations, and storing them in a collection like a HashMap. You then select and execute the desired strategy at runtime by looking up the appropriate trait object.

Why use the strategy pattern instead of conditional logic for authentication modes?

Use the strategy pattern instead of conditional logic for authentication modes to make behavior pluggable and extensible. It encapsulates each authentication algorithm behind a common interface, allowing you to register or select modes at runtime without expanding a switch statement.

Can I use function-based strategies instead of classes in TypeScript?

Yes, you can use function-based strategies in TypeScript. The strategy pattern supports both function-based and class-based approaches, allowing you to define interchangeable algorithms as typed functions that conform to a shared signature for runtime selection.