agentleFS
andr-caandr-ca/agentharness/.claude/skills/solid-principles/SKILL.md

solid-principles

Skill1 starsChanged 2 months agoMITView on GitHub

Use when designing classes or APIs to evaluate SOLID compliance — SRP, OCP, LSP, ISP, DIP. Covers what each principle means, how to diagnose violations by symptom, and how to refactor.

11 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

3 rules. 0 are common, 2 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 9 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Add behavior by adding code, not by editing existing code.

    line 44
  2. Very specific:

    If B extends A, code using A must work with B without knowing the difference.

    line 69
  3. Distinctive:

    Prefer many small interfaces over one large one.

    line 92

“Common” is measured: kept by at least 6 in 10 of the 9 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

SOLID Principles

Five principles for writing code that's easy to change.


S — Single Responsibility Principle

A class should have one reason to change.

One class doing two unrelated things = two reasons to change it.

# Violation: UserService handles auth AND notifications
class UserService:
    def login(self, email, password): ...
    def send_welcome_email(self, user): ...  # belongs elsewhere

# Better
class AuthService:
    def login(self, email, password): ...

class UserNotifier:
    def send_welcome(self, user): ...

Signal: method names have unrelated verbs; the class imports from many unrelated modules.


O — Open/Closed Principle

Open for extension, closed for modification.

Add behavior by adding code, not by editing existing code.

// Violation: every new payment method requires editing
function processPayment(type: string, amount: number) {
    if (type === 'card') { ... }
    if (type === 'crypto') { ... }  // keep adding ifs
}

// Better: polymorphism or strategy
interface PaymentProcessor {
    process(amount: number): Promise<void>;
}
class CardProcessor implements PaymentProcessor { ... }
class CryptoProcessor implements PaymentProcessor { ... }

Signal: feature additions require editing a switch/if-else chain in a stable class.


L — Liskov Substitution Principle

Subtypes must be substitutable for their supertypes.

If B extends A, code using A must work with B without knowing the difference.

# Violation: Square breaks Rectangle invariants
class Rectangle:
    def set_width(self, w): self.width = w
    def set_height(self, h): self.height = h
    def area(self): return self.width * self.height

class Square(Rectangle):
    def set_width(self, w):
        self.width = w
        self.height = w  # breaks Rectangle callers who set W and H independently

Signal: overriding a method throws an exception, does nothing, or changes invariants the parent declares.


I — Interface Segregation Principle

Clients should not depend on methods they don't use.

Prefer many small interfaces over one large one.

// Violation: Printer forced to implement fax
interface Machine {
    print(doc: Document): void;
    scan(doc: Document): void;
    fax(doc: Document): void;   // not all machines fax
}

// Better
interface Printer { print(doc: Document): void; }
interface Scanner { scan(doc: Document): void; }

Signal: a class implements an interface but leaves methods empty or throws NotImplementedError.


D — Dependency Inversion Principle

Depend on abstractions, not concretions. High-level modules must not depend on low-level modules; both should depend on abstractions.

# Violation: high-level OrderService knows about MySQL
from mysql_connector import MySQLDatabase

class OrderService:
    def __init__(self):
        self.db = MySQLDatabase()  # low-level detail

# Better
class OrderRepository(Protocol):
    def save(self, order: Order) -> None: ...

class OrderService:
    def __init__(self, repo: OrderRepository) -> None:
        self.repo = repo

See .claude/skills/dependency-injection/SKILL.md for the full DI pattern.


Quick Diagnosis

SymptomLikely principle violated
One class file is hundreds of linesSRP
Every new feature requires editing many existing filesOCP
Subclass throws NotImplementedError on some parent methodsLSP
Class implements an interface but leaves half the methods emptyISP
Business logic imports database/framework classes directlyDIP

See Also

  • patterns/solid-principles/README.md — pattern directory entry
  • .claude/skills/dependency-injection/SKILL.md — DIP in practice
  • .claude/skills/design-patterns/SKILL.md — patterns that implement SOLID

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.