Agent Skills: Strategy Pattern

Use the Strategy pattern to select behavior at runtime; bind multiple implementations to a shared interface

UncategorizedID: noartem/laravel-vue-skills/laravel-strategy-pattern

Install this agent skill to your local

pnpm dlx add-skill https://github.com/noartem/skills/tree/HEAD/skills/laravel-strategy-pattern

Skill Files

Browse the full folder contents for laravel-strategy-pattern.

Download Skill

Loading file tree…

skills/laravel-strategy-pattern/SKILL.md

Skill Metadata

Name
laravel-strategy-pattern
Description
Use the Strategy pattern to select behavior at runtime; bind multiple implementations to a shared interface

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.