Strategy pattern

From jpcaparas/superpowers-laravel · View interactive version

Strategy pattern is an AI agent skill from the GitHub repository jpcaparas/superpowers-laravel. Use the Strategy pattern to select behavior at runtime; bind multiple implementations to a shared interface

How to use this skill

Skill file

Strategy Pattern

Create a common interface and multiple implementations. Choose a strategy by key or context.

interface TaxCalculator { public function for(int $cents): int; }
final class NzTax implements TaxCalculator { /* ... */ }
final class AuTax implements TaxCalculator { /* ... */ }

final class TaxFactory {
  public function __construct(private array $drivers) {}
  public function forCountry(string $code): TaxCalculator { return $this->drivers[$code]; }
}

Register in a service provider and inject the factory where needed.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.