skills/software-engineering/design-principles/solid-principles/SKILL.md
Apply SOLID principles (SRP, OCP, LSP, ISP, DIP) for tactical class design, method extraction, and interface definition. Use when reviewing class design, refactoring code for maintainability, or designing interfaces and abstractions.
npx skillsauth add pantheon-org/tekhne solid-principlesInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Tactical design principles for class-level decisions, interface design, and dependency management.
Apply during code review or design:
| Principle | Check | Refactor Signal | | --- | --- | --- | | SRP | Does this class have one reason to change? | Multiple concerns → split into focused classes | | OCP | Can you extend behavior without modifying existing code? | Adding features requires editing stable code → use abstraction | | LSP | Do subtypes preserve base behavior contracts? | Subtype breaks parent assumptions → redesign hierarchy | | ISP | Do clients depend only on methods they use? | Clients ignore many interface methods → split interface | | DIP | Do you depend on abstractions, not concrete details? | Direct concrete coupling → introduce interface/port |
Output: List of classes with multiple reasons to change.
Ask for each class:
Example:
SRP violation: UserService handles auth, persistence, and notifications.
Refactor: Extract NotificationService and PersistenceGateway.
Validation: Each class now has one reason to change.
Output: List of areas where new features require modifying stable code.
Ask:
Example:
OCP violation: Adding payment processor requires editing PaymentService.
Refactor: Extract PaymentProcessor interface + implementations.
Validation: New processors added without touching existing code.
Output: Subtypes that break base type contracts.
Check:
Example:
LSP violation: CachedRepository.save() throws exception when cache is full.
Refactor: Base Repository contract promises no exceptions; use Result type instead.
Output: Interfaces split by client needs.
Check:
Example:
ISP violation: IUserRepository has save(), find(), and sendNotification().
Refactor: Split into IUserRepository and INotificationService.
Output: Abstractions introduced at module boundaries.
Check:
Example:
DIP violation: OrderService instantiates PostgresRepository.
Refactor: OrderService depends on IOrderRepository interface.
Injection: Container provides PostgresRepository implementation.
# Find SRP violations (multiple concerns)
rg -n "class.*Service.*Repository|class.*Manager.*Handler" src
# Find OCP violations (type checks)
rg -n "instanceof|typeof.*==|switch.*type" src
# Find DIP violations (concrete instantiation)
rg -n "new [A-Z].*Repository\(|new [A-Z].*Service\(" src
UserManager class that handles authentication, profile editing, email notifications, and audit logging — violating SRP by having four distinct reasons to change.AuthService, UserProfileService, NotificationService, and AuditLog with clear single responsibilities and independent change trajectories.ICanSave, ICanFind, ICanDelete) that are always implemented and injected together.class PremiumUser extends AuthenticatedUser extends User extends BaseUser to add behavior, creating a four-level hierarchy where changing any layer risks breaking all subclasses.new User(new PremiumFeatureSet()) — open for extension by adding new feature sets, closed for modification of the User class itself.SOLID principles are tactical class-level design rules. For architectural decisions (boundaries, modules, dependencies), use the clean-architecture skill.
For detailed SOLID guidance, see the software-design-principles hub (references/detailed-examples.md, references/anti-patterns-and-frameworks.md).
tools
A skill that produces warnings but no errors.
testing
A well-formed example skill for testing the validator.
development
A skill with code blocks and imperative instructions for testing content and contamination analysis.
tools