agentleFS
VelimirMuellerVelimirMueller/ai-development-skills/skills/craft/apply-design-principles/SKILL.md

apply-design-principles

Skill7 starsChanged 16 days agoMITView on GitHub

Use when writing or reviewing class or module design — encapsulate what varies, program to an interface, favor composition over inheritance, keep class and type distinct, and obey the Law of Demeter and the Hollywood Principle.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Every principle has a "when to break" line.

    line 54

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “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

Apply Design Principles

The durable object-oriented rules behind every pattern, as a review checklist. They are the "why" the patterns exist. Catalogue of the patterns themselves: patterns-catalogue.md.

The principles

  1. Encapsulate what varies. Identify the part that changes and isolate it behind a boundary; change to that part no longer ripples. Ask of every new module: what here will change, and is it fenced off.
  2. Program to an interface, not a concrete class. Depend on the behaviour you need, not the specific type that happens to provide it. A function that takes a shape instead of a class stays usable with any compatible shape.
  3. Favor composition over inheritance. Composition is black-box reuse (runtime, keeps encapsulation); inheritance is white-box reuse (compile-time, breaks encapsulation). Prefer "has-a" over "is-a"; reach for inheritance only for a genuine subtype relationship.
  4. Class ≠ type. A class is one implementation; a type is the interface it satisfies. Two classes can share a type without sharing code. Under structural typing any object with the compatible shape satisfies the interface — no subclass required.
  5. Principle of Least Knowledge (Law of Demeter). Talk only to immediate friends. A method should call methods on its own object, its arguments, and objects it creates — never the friends of a friend (a.b.c.d()). This keeps coupling shallow and change local.
  6. Hollywood Principle (Inversion of Control). "Don't call us, we'll call you." High-level policy calls the low-level detail, not the reverse. Let the framework/host drive; supply the hook.
  7. Open/Closed. Open for extension, closed for modification: add new behaviour by adding code, not by editing existing code, so the stable part stops accumulating churn.
  8. Dependency Inversion. Depend on abstractions, not concretions; high-level policy never depends on low-level details, both depend on abstractions. Details (DB, web, framework) point inward toward policy.

1. Audit (change nothing)

cat .claude/stack-profile.md 2>/dev/null | head -20
grep -rn "extends\|class.*extends\|a\.b\.c\." --include="*.ts" --include="*.rs" --include="*.go" --include="*.py" . 2>/dev/null | head -30

Find the violation first: an inheritance chain that exists for reuse, a chain of method calls through three collaborators, a module that imports a concrete vendor type everywhere, a policy that imports a framework.

2. Apply the smallest fix

  • A type that changes together → one module that owns it (encapsulate what varies).
  • A parameter typed to a concrete class → type it to the interface/shape it uses.
  • A subclass used only for reuse → a composed field or a function.
  • A a.b.c() chain → a method on the friend that owns the traversal.

3. State the exception

Every principle has a "when to break" line. Record why the violation is the honest choice (performance, the framework's own convention, a throwaway) instead of silently leaving it.

Verify

The change that used to touch many files now touches one; a second subclass was added without editing the base; the import of a vendor SDK is confined to one seam. State the trade-off in the review note.

When to deviate

  • A tiny, stable, single-author codebase where a principle's ceremony outweighs its benefit.
  • The language or framework idiom contradicts the classic form (structural typing, DI containers, composition-over-inheritance in Rust) — follow the idiom, keep the intent.

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.