From playbooks-virtuoso
Reviews and refactors object-oriented code for SOLID compliance in PHP, Java, Python, TypeScript, C++. Detects violations of SRP, OCP, LSP, ISP, DIP and suggests fixes with examples.
npx claudepluginhub krzysztofsurdy/code-virtuoso --plugin playbooks-virtuosoThis skill is limited to using the following tools:
Five core principles of object-oriented design that lead to systems which are simpler to maintain, test, and extend. Robert C. Martin (Uncle Bob) formalized these ideas, and Michael Feathers coined the SOLID acronym.
Applies SOLID principles (SRP, OCP) with Elixir and TypeScript examples for designing maintainable modules, functions, and components.
Provides SOLID principles (SRP, OCP, LSP, ISP, DIP) reference for PHP 8.4 with bash detection patterns, examples, and violation signs for audits and reviews.
Provides language-agnostic SOLID principles, design patterns, DRY, KISS guidelines for code reviews, architecture analysis, refactoring, and design decisions.
Share bugs, ideas, or general feedback.
Five core principles of object-oriented design that lead to systems which are simpler to maintain, test, and extend. Robert C. Martin (Uncle Bob) formalized these ideas, and Michael Feathers coined the SOLID acronym.
| Principle | Summary | Reference |
|---|---|---|
| S — Single Responsibility | A class should have only one reason to change | reference |
| O — Open/Closed | Open for extension, closed for modification | reference |
| L — Liskov Substitution | Subtypes must be substitutable for their base types | reference |
| I — Interface Segregation | Prefer many specific interfaces over one general-purpose interface | reference |
| D — Dependency Inversion | Depend on abstractions, not concretions | reference |
Without SOLID, codebases gradually develop these problems:
SOLID tackles each of these by defining clear boundaries, explicit contracts, and flexible points for extension.
| Symptom | Likely Violated Principle | Fix |
|---|---|---|
| Class does too many things | SRP | Split into focused classes |
| Adding a feature requires editing existing classes | OCP | Introduce polymorphism or strategy |
| Subclass breaks when used in place of parent | LSP | Fix inheritance hierarchy or use composition |
| Classes forced to implement unused methods | ISP | Break interface into smaller ones |
| High-level module imports low-level details | DIP | Introduce an abstraction layer |
// BEFORE: Class handles both user data AND email sending
class UserService {
public function createUser(string $name, string $email): void { /* ... */ }
public function sendWelcomeEmail(string $email): void { /* ... */ }
}
// AFTER: Each class has one responsibility
class UserService {
public function __construct(private UserNotifier $notifier) {}
public function createUser(string $name, string $email): void {
// persist user...
$this->notifier->welcomeNewUser($email);
}
}
class UserNotifier {
public function welcomeNewUser(string $email): void { /* ... */ }
}
interface DiscountPolicy {
public function calculate(float $total): float;
}
class PercentageDiscount implements DiscountPolicy {
public function __construct(private float $rate) {}
public function calculate(float $total): float {
return $total * $this->rate;
}
}
// Adding a new discount type requires NO changes to existing code
class FlatDiscount implements DiscountPolicy {
public function __construct(private float $amount) {}
public function calculate(float $total): float {
return min($this->amount, $total);
}
}
// High-level policy depends on abstraction, not on database details
interface OrderRepository {
public function save(Order $order): void;
}
class PlaceOrderHandler {
public function __construct(private OrderRepository $repository) {}
public function handle(PlaceOrderCommand $cmd): void {
$order = Order::create($cmd->items);
$this->repository->save($order);
}
}
The five principles complement and reinforce one another: