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.
1---2name: laravel-strategy-pattern3description: Strategy Pattern4---5# Strategy Pattern67Create a common interface and multiple implementations. Choose a strategy by key or context.89```php10interface TaxCalculator { public function for(int $cents): int; }11final class NzTax implements TaxCalculator { /* ... */ }12final class AuTax implements TaxCalculator { /* ... */ }1314final class TaxFactory {15 public function __construct(private array $drivers) {}16 public function forCountry(string $code): TaxCalculator { return $this->drivers[$code]; }17}18```1920Register in a service provider and inject the factory where needed.
Run npx skillmds@latest add comeonoliver/laravel-strategy-pattern in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Strategy Pattern It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. Independent scanners report: SkillSpector: PASS, Skill Scanner: PASS. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
ComeOnOliver (@comeonoliver) published this skill. Their other Agent Skills are listed on their SkillMD profile.