solid-principles
SOLID object-oriented design principles for maintainable code
Best use case
solid-principles is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
SOLID object-oriented design principles for maintainable code
Teams using solid-principles should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/solid-principles/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How solid-principles Compares
| Feature / Agent | solid-principles | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
SOLID object-oriented design principles for maintainable code
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# SOLID Principles
Five principles for object-oriented design that lead to maintainable, extensible software.
## S - Single Responsibility Principle
> A class should have only one reason to change.
```typescript
// BAD - multiple responsibilities
class UserService {
createUser(data: UserData) { /* ... */ }
sendEmail(user: User, message: string) { /* ... */ }
generateReport(users: User[]) { /* ... */ }
validateEmail(email: string) { /* ... */ }
}
// GOOD - single responsibility each
class UserService {
constructor(
private repository: UserRepository,
private validator: UserValidator
) {}
createUser(data: UserData): User {
this.validator.validate(data);
return this.repository.save(data);
}
}
class EmailService {
send(to: string, message: string) { /* ... */ }
}
class UserReportGenerator {
generate(users: User[]): Report { /* ... */ }
}
class EmailValidator {
validate(email: string): boolean { /* ... */ }
}
```
**When to apply:** If you describe a class with "and" (UserService creates users AND sends emails AND...), split it.
## O - Open/Closed Principle
> Open for extension, closed for modification.
```typescript
// BAD - must modify class to add new types
class PaymentProcessor {
process(payment: Payment) {
if (payment.type === 'credit') {
// process credit card
} else if (payment.type === 'paypal') {
// process PayPal
} else if (payment.type === 'crypto') {
// process crypto - had to modify!
}
}
}
// GOOD - extend without modification
interface PaymentMethod {
process(amount: number): Promise<Receipt>;
}
class CreditCardPayment implements PaymentMethod {
async process(amount: number): Promise<Receipt> {
// credit card logic
}
}
class PayPalPayment implements PaymentMethod {
async process(amount: number): Promise<Receipt> {
// PayPal logic
}
}
// Adding crypto doesn't modify existing code
class CryptoPayment implements PaymentMethod {
async process(amount: number): Promise<Receipt> {
// crypto logic
}
}
class PaymentProcessor {
process(method: PaymentMethod, amount: number) {
return method.process(amount);
}
}
```
**When to apply:** When adding new features requires modifying existing, tested code.
## L - Liskov Substitution Principle
> Subtypes must be substitutable for their base types.
```typescript
// BAD - Square violates Rectangle contract
class Rectangle {
constructor(protected width: number, protected height: number) {}
setWidth(width: number) { this.width = width; }
setHeight(height: number) { this.height = height; }
getArea() { return this.width * this.height; }
}
class Square extends Rectangle {
setWidth(width: number) {
this.width = width;
this.height = width; // Violates expectation!
}
setHeight(height: number) {
this.width = height;
this.height = height; // Violates expectation!
}
}
// This breaks:
function doubleWidth(rect: Rectangle) {
const originalHeight = rect.getArea() / rect.width;
rect.setWidth(rect.width * 2);
// For Square, height also doubled - unexpected!
}
// GOOD - separate hierarchies
interface Shape {
getArea(): number;
}
class Rectangle implements Shape {
constructor(private width: number, private height: number) {}
getArea() { return this.width * this.height; }
}
class Square implements Shape {
constructor(private side: number) {}
getArea() { return this.side * this.side; }
}
```
**When to apply:** If subclass overrides change behavior that callers depend on.
## I - Interface Segregation Principle
> Clients should not depend on interfaces they don't use.
```typescript
// BAD - fat interface
interface Worker {
work(): void;
eat(): void;
sleep(): void;
attendMeeting(): void;
writeReport(): void;
}
class Robot implements Worker {
work() { /* ... */ }
eat() { throw new Error('Robots do not eat'); } // Forced to implement!
sleep() { throw new Error('Robots do not sleep'); }
attendMeeting() { throw new Error('Not applicable'); }
writeReport() { throw new Error('Not applicable'); }
}
// GOOD - segregated interfaces
interface Workable {
work(): void;
}
interface Feedable {
eat(): void;
}
interface Sleepable {
sleep(): void;
}
interface MeetingAttendee {
attendMeeting(): void;
}
class Human implements Workable, Feedable, Sleepable, MeetingAttendee {
work() { /* ... */ }
eat() { /* ... */ }
sleep() { /* ... */ }
attendMeeting() { /* ... */ }
}
class Robot implements Workable {
work() { /* ... */ }
}
```
**When to apply:** When classes implement methods they don't need, or throw "not implemented" errors.
## D - Dependency Inversion Principle
> Depend on abstractions, not concretions.
```typescript
// BAD - high-level depends on low-level
class MySQLDatabase {
query(sql: string) { /* ... */ }
}
class UserRepository {
private db = new MySQLDatabase(); // Tight coupling!
findById(id: string) {
return this.db.query(`SELECT * FROM users WHERE id = '${id}'`);
}
}
// GOOD - both depend on abstraction
interface Database {
query<T>(sql: string): Promise<T>;
}
class MySQLDatabase implements Database {
async query<T>(sql: string): Promise<T> { /* ... */ }
}
class PostgreSQLDatabase implements Database {
async query<T>(sql: string): Promise<T> { /* ... */ }
}
class UserRepository {
constructor(private db: Database) {} // Injected!
findById(id: string) {
return this.db.query(`SELECT * FROM users WHERE id = '${id}'`);
}
}
// Easy to swap implementations
const repo = new UserRepository(new PostgreSQLDatabase());
```
**When to apply:** When testing is hard, or changing one module breaks others.
## SOLID in Practice
### Recognizing Violations
| Principle | Code Smell |
|-----------|------------|
| SRP | Class has many unrelated methods |
| OCP | Adding feature requires modifying existing code |
| LSP | Subclass throws "not supported" or behaves differently |
| ISP | Class implements methods it doesn't use |
| DIP | `new` keyword scattered throughout business logic |
### Applying SOLID
1. **Start simple** - Don't over-engineer from day one
2. **Refactor when needed** - Apply when you feel the pain
3. **Use dependency injection** - Makes DIP natural
4. **Prefer composition** - Over inheritance (helps LSP)
5. **Write small interfaces** - Easier than splitting later
### Balance
SOLID is a guide, not law. Over-applying creates:
- Too many tiny classes
- Indirection that's hard to follow
- Abstractions nobody needs yet
Apply SOLID when:
- Code is hard to test
- Changes ripple through the codebase
- Similar changes needed in multiple places
- You're adding the 3rd variation of something
## Checklist
- [ ] Does each class have a single, clear purpose?
- [ ] Can I add features without modifying existing code?
- [ ] Can subclasses replace parent classes safely?
- [ ] Are interfaces focused and minimal?
- [ ] Are dependencies injected, not created internally?Related Skills
<essential_principles>
**Culture Index measures behavioral traits, not intelligence or skills. There is no "good" or "bad" profile.**
robotics-software-principles
Foundational software design principles applied specifically to robotics module development. Use this skill when designing robot software modules, structuring codebases, making architecture decisions, reviewing robotics code, or building reusable robotics libraries. Trigger whenever the user mentions SOLID principles for robots, modular robotics software, clean architecture for robots, dependency injection in robotics, interface design for hardware, real-time design constraints, error handling strategies for robots, configuration management, separation of concerns in perception-planning- control, composability of robot behaviors, or any discussion of software craftsmanship in a robotics context. Also trigger for code reviews of robotics code, refactoring robot software, or designing APIs for robotics libraries.
api-design-principles
Master REST and GraphQL API design principles to build intuitive, scalable, and maintainable APIs that delight developers. Use when designing new APIs, reviewing API specifications, or establishing API design standards.
principles
Provides development principles, guidelines, and VibeCoder guidance. Use when user mentions 原則, principles, ガイドライン, guidelines, VibeCoder, 安全性, safety, 差分編集, diff-aware. Triggers: 原則, principles, ガイドライン, VibeCoder, 安全性, 差分編集. Do not use for actual implementation - use impl skill instead.
ai-chapter-consolidate
Use AI to merge individual page HTML files into a unified chapter document. Creates continuous document format for improved reading experience and semantic consistency.
Solidity
## Overview
SolidJS
SolidJS uses fine-grained reactivity with signals — no virtual DOM diffing. Components run once, and only the specific DOM nodes that depend on changed signals update. This makes it extremely fast.
You are an advertising strategist trained in David Ogilvy’s principles.
Task:
solidity-testing
[AUTO-INVOKE] MUST be invoked BEFORE writing or modifying any test files (*.t.sol). Covers test structure, naming conventions, coverage requirements, fuzz testing, and Foundry cheatcodes. Trigger: any task involving creating, editing, or running Solidity tests.
solidity-security
[AUTO-INVOKE] MUST be invoked BEFORE writing or modifying any Solidity contract (.sol files). Covers private key handling, access control, reentrancy prevention, gas safety, and pre-audit checklists. Trigger: any task involving creating, editing, or reviewing .sol source files.
solidity-deploy
[AUTO-INVOKE] MUST be invoked BEFORE deploying contracts or writing deployment scripts (*.s.sol). Covers pre-flight checks, forge script commands, post-deployment validation, and verification. Trigger: any task involving forge script, contract deployment, or block explorer verification.
solidity-debug
[AUTO-INVOKE] MUST be invoked when debugging failed on-chain transactions. Covers transaction receipt analysis, gas diagnosis, calldata decoding, revert reason extraction, and state verification. Trigger: any task involving failed tx analysis, revert debugging, or on-chain transaction troubleshooting.