agentleFS
luckysluckys/agent-skills/skills/oop-best-practices/SKILL.md

oop-best-practices

Skill5 starsChanged 30 days agoMITView on GitHub

Use when designing or reviewing object responsibilities, naming, encapsulation, value-object equality, immutability, parsing or normalization, collections, cohesion, dependency direction, Tell Don't Ask, Law of Demeter, Object Calisthenics, SOLID, or composition versus inheritance. Focuses on everyday object design; use DDD for context boundaries and pattern guidance for named pattern selection.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

44 rules. About 0 are common, 21 are distinctive, and 23 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈21

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 23

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this skill for everyday coding decisions that shape readability, cohesion, and long-term maintainability.

    line 12
  2. Distinctive:

    Use it especially when the task benefits from:

    line 14
  3. Distinctive:

    Write code for the next reader, not just for the compiler.

    line 23
  4. Distinctive:

    Keep behavior close to the concept that owns it.

    line 24
  5. Distinctive:

    Prefer simple collaborations over clever object graphs.

    line 25
  6. Distinctive:

    Use names, boundaries, and APIs to reveal intent.

    line 26
  7. Distinctive:

    If a name is weak, question the abstraction before polishing the wording.

    line 56
  8. Distinctive:

    Avoid premature abstractions that erase the concept or guess too much future reuse.

    line 57
  9. Distinctive:

    Remove duplicated knowledge, not merely duplicated syntax.

    line 58
  10. Distinctive:

    Prefer rich objects over data carriers when the concept has meaningful behavior.

    line 63
  11. Distinctive:

    Prefer asking collaborators for meaningful behavior over pulling data out.

    line 68
  12. Distinctive:

    Keep public interfaces small, explicit, and intention revealing.

    line 70
  13. Distinctive:

    Prefer composition when behavior changes independently.

    line 74
  14. Distinctive:

    Keep inheritance shallow and honest.

    line 75
  15. Distinctive:

    Avoid object graphs that force train-wreck navigation.

    line 76
  16. Distinctive:

    Prefer intention-revealing names over short names.

    line 80
  17. Distinctive:

    Keep methods shallow and centered on one level of abstraction.

    line 81
  18. Distinctive:

    Use early returns when they reduce branching noise.

    line 82
  19. Distinctive:

    Keep classes cohesive instead of merely small.

    line 83
  20. Distinctive:

    Prefer telling collaborators what to do over asking for their data and deciding elsewhere.

    line 85
  21. Distinctive:

    Keep public APIs smaller than internal implementation detail.

    line 90
  22. Very specific:

    Read references/interface-depth.md when assessing interface complexity, pass-through layers, or the state a caller must track.

    line 110
  23. Very specific:

    Read references/core-principles.md for condensed coding heuristics.

    line 112
  24. Very specific:

    Read references/book-influences.md for a source-oriented map of the key books behind this skill.

    line 113
  25. Very specific:

    Read references/naming-and-abstractions.md when naming or abstraction quality is the main issue.

    line 114
  26. Very specific:

    Read references/message-based-design.md when object collaboration and roles matter most.

    line 115
  27. Very specific:

    Read references/advanced-modeling-concepts.md for richer object choices that still stay within everyday OO design.

    line 116
  28. Very specific:

    Read references/fran-iglesias-practical-guidance.md for practical OO heuristics distilled from Fran Iglesias.

    line 117
  29. Very specific:

    Read references/solid-principles.md when SOLID violations or design pressure around single responsibility, open-closed, or dependency …

    line 118
  30. Very specific:

    Read references/object-calisthenics.md when applying strict OO discipline rules to clean up a class or method.

    line 119
  31. Very specific:

    Read references/dependency-management.md when coupling, dependency direction, or collaborator injection decisions are the focus.

    line 120
  32. Very specific:

    Read references/method-design.md when method length, abstraction level, or intention-revealing structure is the problem.

    line 121
  33. Very specific:

    Read references/gradual-abstraction.md when the right moment to introduce abstraction is unclear or the design is being over-engineered too …

    line 122
  34. Very specific:

    Read references/language-examples.md for an index of language-specific example files (TypeScript, Java, Python, C#, Ruby, PHP, Go, Rust).

    line 123
  35. Very specific:

    Read references/go-examples.md for OOP concepts in Go (structs, implicit interfaces, composition, no inheritance).

    line 124
  36. Very specific:

    Read references/rust-examples.md for OOP concepts in Rust (structs, traits, newtype pattern, ownership as immutability).

    line 125
  37. Very specific:

    Read references/simple-design-rules.md for Kent Beck's 4 Rules of Simple Design: passes tests, reveals intention, no duplication, fewest …

    line 126
  38. Very specific:

    Read references/oop-good-practices-examples.md for corrected cross-language lessons on Demeter, Tell Don't Ask, named construction, …

    line 127
  39. Very specific:

    Read references/value-objects-advanced.md as the canonical Value Object guide: selection criteria, invariant ownership, …

    line 128
  40. Very specific:

    Use ddd-best-practices when object ownership also defines a consistency, lifecycle, repository, or transaction boundary.

    line 132
  41. Very specific:

    Use tdd-best-practices for Value Object contract tests, boundary analysis, property-based tests, and deterministic fixtures.

    line 133
  42. Very specific:

    Use refactoring-best-practices for risky or legacy code changes.

    line 134
  43. Very specific:

    Use design-patterns-best-practices when the main question is pattern selection.

    line 135
  44. Very specific:

    Use rest-api-best-practices when designing the HTTP API surface that exposes these objects.

    line 136

≈ “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

OOP Best Practices

Use this skill for everyday coding decisions that shape readability, cohesion, and long-term maintainability.

Use it especially when the task benefits from:

  • stronger naming and more explicit abstractions
  • clearer object responsibilities and encapsulated invariants
  • message-based collaboration and role-oriented objects
  • composition over inheritance in everyday design choices

Working Style

  1. Write code for the next reader, not just for the compiler.
  2. Keep behavior close to the concept that owns it.
  3. Prefer simple collaborations over clever object graphs.
  4. Use names, boundaries, and APIs to reveal intent.
  5. Let objects carry their own rules when they can.

Review Workflow

  1. Identify the concept.
    • What concept is this code modeling?
    • What rules or invariants belong to that concept?
  2. Check the boundary.
    • Is the object exposing raw data or meaningful behavior?
    • Are callers forced to know too much about internal structure?
  3. Check the shape.
    • Are methods mixing multiple abstraction levels?
    • Is the class carrying more than one reason to change?
    • Are names explicit enough to understand intent quickly?
  4. Apply the lightest useful improvement.
    • rename for clarity
    • extract method
    • extract value object
    • extract first-class collection
    • move behavior to the object that owns the data
    • split the class by responsibility

Additional Review Lenses

Naming and abstraction discipline

  • If a name is weak, question the abstraction before polishing the wording.
  • Avoid premature abstractions that erase the concept or guess too much future reuse.
  • Remove duplicated knowledge, not merely duplicated syntax.

Encapsulation and object responsibility

  • Move rules to the concept that owns them.
  • Prefer rich objects over data carriers when the concept has meaningful behavior.
  • Let services orchestrate when objects can own the rule.

Message-based design

  • Prefer asking collaborators for meaningful behavior over pulling data out.
  • Depend on roles and messages rather than concrete internal structure.
  • Keep public interfaces small, explicit, and intention revealing.

Structural simplicity

  • Prefer composition when behavior changes independently.
  • Keep inheritance shallow and honest.
  • Avoid object graphs that force train-wreck navigation.

Day-to-Day Rules

  • Prefer intention-revealing names over short names.
  • Keep methods shallow and centered on one level of abstraction.
  • Use early returns when they reduce branching noise.
  • Keep classes cohesive instead of merely small.
  • Introduce a Value Object when identity does not matter and semantic guarantees, type safety, or behavior justify a domain type.
  • Prefer telling collaborators what to do over asking for their data and deciding elsewhere.
  • Introduce first-class collections when collections have their own invariants.
  • Give Value Objects semantic equality, matching hash behavior, and deeply immutable observation; do not rely on object-reference equality or shallow readonly.
  • Depend on small roles instead of volatile concrete details.
  • Prefer composition when behavior changes independently.
  • Keep public APIs smaller than internal implementation detail.

Good Signals

  • The class name matches the behavior it owns.
  • Invalid states are rejected early.
  • Most methods can be understood without reading unrelated helpers.
  • Callers depend on a small surface area.
  • The same concept is named consistently across the codebase.

Warning Signs

  • A method needs several comments to be readable.
  • A class mostly exposes getters and setters.
  • Many callers repeat the same validation or branching logic.
  • A change in one concept forces edits across many unrelated files.
  • The object model looks like data transport with behavior bolted on elsewhere.

References

  • Read references/interface-depth.md when assessing interface complexity, pass-through layers, or the state a caller must track.
  • Read references/core-principles.md for condensed coding heuristics.
  • Read references/book-influences.md for a source-oriented map of the key books behind this skill.
  • Read references/naming-and-abstractions.md when naming or abstraction quality is the main issue.
  • Read references/message-based-design.md when object collaboration and roles matter most.
  • Read references/advanced-modeling-concepts.md for richer object choices that still stay within everyday OO design.
  • Read references/fran-iglesias-practical-guidance.md for practical OO heuristics distilled from Fran Iglesias.
  • Read references/solid-principles.md when SOLID violations or design pressure around single responsibility, open-closed, or dependency inversion are the main issue.
  • Read references/object-calisthenics.md when applying strict OO discipline rules to clean up a class or method.
  • Read references/dependency-management.md when coupling, dependency direction, or collaborator injection decisions are the focus.
  • Read references/method-design.md when method length, abstraction level, or intention-revealing structure is the problem.
  • Read references/gradual-abstraction.md when the right moment to introduce abstraction is unclear or the design is being over-engineered too early.
  • Read references/language-examples.md for an index of language-specific example files (TypeScript, Java, Python, C#, Ruby, PHP, Go, Rust).
  • Read references/go-examples.md for OOP concepts in Go (structs, implicit interfaces, composition, no inheritance).
  • Read references/rust-examples.md for OOP concepts in Rust (structs, traits, newtype pattern, ownership as immutability).
  • Read references/simple-design-rules.md for Kent Beck's 4 Rules of Simple Design: passes tests, reveals intention, no duplication, fewest elements — with CodelyTV examples.
  • Read references/oop-good-practices-examples.md for corrected cross-language lessons on Demeter, Tell Don't Ask, named construction, collection identity, dependency roles, and course counterexamples.
  • Read references/value-objects-advanced.md as the canonical Value Object guide: selection criteria, invariant ownership, construction/parsing, equality and hashing, deep immutability, behavior, optionality, first-class collections, persistence, testing, and safe evolution.

Related Skills

  • Use ddd-best-practices when object ownership also defines a consistency, lifecycle, repository, or transaction boundary.
  • Use tdd-best-practices for Value Object contract tests, boundary analysis, property-based tests, and deterministic fixtures.
  • Use refactoring-best-practices for risky or legacy code changes.
  • Use design-patterns-best-practices when the main question is pattern selection.
  • Use rest-api-best-practices when designing the HTTP API surface that exposes these objects.

Source Influences

This skill is synthesized from ideas emphasized in:

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.