agentleFS
kayamankayaman/skills/oop-design-patterns/SKILL.md

oop-design-patterns

Skill3 starsChanged 8 months agoCC0-1.0View on GitHub

Comprehensive knowledge base covering the main topics from the most influential Object-Oriented Programming books. Use when the user asks about OOP principles, design patterns, SOLID, refactoring, clean code, object thinking, or object-oriented analysis and design. Also useful when reviewing code for OOP best practices, discussing trade-offs like composition vs inheritance, or applying design patterns to solve structural problems.

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 3 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    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 major OOP book builds on four pillars.

    line 28
  2. Distinctive:

    Use inheritance for genuine type hierarchies.

    line 159
  3. Distinctive:

    Use tests to drive the discovery of object interfaces and collaborations.

    line 192

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

Object-Oriented Programming — Core Topics from the Best Books

This skill synthesizes the main topics covered by the most influential and widely recommended books on Object-Oriented Programming, analysis, and design. It is organized around the recurring themes that appear across the canon rather than as a book-by-book summary.

Foundational OOP Concepts

Every major OOP book builds on four pillars. Understanding these is a prerequisite for everything else in the discipline.

  1. Abstraction — Modeling real-world entities by exposing only relevant details and hiding complexity. Objects represent concepts, not implementation.
  2. Encapsulation — Bundling data and the methods that operate on it into a single unit, restricting direct access to internal state. Protects invariants and reduces coupling.
  3. Inheritance — Defining new classes based on existing ones to promote code reuse. Best used for expressing genuine "is-a" relationships, not mere convenience.
  4. Polymorphism — Allowing objects of different types to respond to the same message in different ways. Enables flexible, extensible systems and eliminates conditional logic (replacing switch statements with polymorphic dispatch).

SOLID Principles

Introduced by Robert C. Martin across several works (Clean Code, Agile Software Development, Clean Architecture), SOLID is the most widely referenced set of OOP design guidelines.

  • Single Responsibility Principle (SRP) — A class should have only one reason to change. Each class encapsulates one cohesive responsibility.
  • Open/Closed Principle (OCP) — Software entities should be open for extension but closed for modification. Add behavior through new code, not by changing existing code.
  • Liskov Substitution Principle (LSP) — Subtypes must be substitutable for their base types without altering the correctness of the program.
  • Interface Segregation Principle (ISP) — Clients should not be forced to depend on interfaces they do not use. Prefer many small, focused interfaces.
  • Dependency Inversion Principle (DIP) — High-level modules should not depend on low-level modules. Both should depend on abstractions.

Design Patterns (Gang of Four)

The 23 patterns catalogued in Design Patterns: Elements of Reusable Object-Oriented Software (Gamma, Helm, Johnson, Vlissides — 1994) remain the most referenced vocabulary in OOP. They are organized into three categories.

Creational Patterns

Concerned with object creation mechanisms: Abstract Factory, Builder, Factory Method, Prototype, Singleton.

Structural Patterns

Concerned with class and object composition: Adapter, Bridge, Composite, Decorator, Facade, Flyweight, Proxy.

Behavioral Patterns

Concerned with communication between objects: Chain of Responsibility, Command, Interpreter, Iterator, Mediator, Memento, Observer, State, Strategy, Template Method, Visitor.

Two Guiding Maxims

The GoF book emphasizes two principles above the individual patterns:

  • "Program to an interface, not an implementation."
  • "Favor object composition over class inheritance."

See design-patterns.md for a detailed breakdown of each pattern with intent and applicability.

Refactoring and Code Smells

Martin Fowler's Refactoring (1999, 2nd ed. 2018) established a disciplined process for improving existing code through small, behavior-preserving transformations. Key topics include:

  • Code smells — Heuristics that indicate structural problems: Long Method, Large Class, Feature Envy, Data Clumps, Primitive Obsession, Shotgun Surgery, Divergent Change, Duplicated Code, and many more.
  • Refactoring catalog — Over 70 named transformations such as Extract Function, Move Field, Replace Conditional with Polymorphism, Encapsulate Collection, and Introduce Parameter Object.
  • The role of testing — Refactoring depends on a solid test suite. Each transformation is small enough that if tests break, the cause is immediately identifiable.
  • When to refactor — Before adding a feature (preparatory refactoring), during code review, when comprehension is difficult, or when performance profiling reveals unnecessary complexity.

Clean Code Practices

Robert C. Martin's Clean Code (2008) focuses on the craft of writing readable, maintainable code at the function and class level. Core topics:

  • Meaningful names — Names should reveal intent, avoid disinformation, and be pronounceable and searchable.
  • Small functions — Functions should do one thing, operate at a single level of abstraction, and have few arguments.
  • Comments — Good code is largely self-documenting. Comments should explain why, not what. Avoid redundant, misleading, or mandated comments.
  • Error handling — Use exceptions rather than error codes. Do not return or pass null. Write try-catch-finally blocks first.
  • Class organization — Classes should be small, have a single responsibility, and exhibit high cohesion.
  • Emergent design — Kent Beck's four rules of simple design: passes all tests, reveals intention, contains no duplication, and has the fewest elements.

Object-Oriented Analysis and Design (OOAD)

Covered extensively by Craig Larman (Applying UML and Patterns), Grady Booch (Object-Oriented Analysis and Design with Applications), and Rebecca Wirfs-Brock (Object Design: Responsibility-Driven Design).

  • Responsibility-Driven Design — Assign responsibilities to objects based on the information they hold or the collaborations they participate in (GRASP patterns: Creator, Information Expert, Low Coupling, High Cohesion, Controller, Polymorphism, Pure Fabrication, Indirection, Protected Variations).
  • CRC cards — Class-Responsibility-Collaboration cards as a design tool for discovering objects and their interactions.
  • Use case analysis — Identifying system behavior from the user's perspective and mapping it to object collaborations.
  • Domain modeling — Creating conceptual models that represent key abstractions in the problem domain.

Composition vs Inheritance

A theme that recurs in nearly every major OOP text:

  • Inheritance creates tight coupling between parent and child classes and can break encapsulation.
  • Composition (delegating behavior to contained objects) provides greater flexibility and looser coupling.
  • Use inheritance for genuine type hierarchies; use composition for assembling behavior from reusable parts.
  • The Strategy and Decorator patterns are classic examples of composition replacing inheritance.

Cohesion and Coupling

Two metrics that indicate design quality, discussed across all major texts:

  • High cohesion — Elements within a module are closely related and focused on a single purpose. Aim for this.
  • Low coupling — Modules have minimal dependencies on each other. Changes to one module should not cascade through the system.
  • These two properties are the most reliable predictors of maintainable, testable software.

Object Thinking and Philosophy

David West's Object Thinking (2004) and Alan Kay's original vision of OOP emphasize that objects are autonomous entities that communicate through messages, not mere data containers with attached procedures. Key ideas:

  • Objects should model real-world concepts and behaviors, not database rows.
  • Message passing (telling objects what to do) is preferable to querying state (asking objects for data and acting on it externally).
  • The "Tell, Don't Ask" principle encourages moving behavior into the object that owns the data.

Test-Driven Development and OOP

Steve Freeman and Nat Pryce's Growing Object-Oriented Software, Guided by Tests (2009) bridges TDD and OOP design:

  • Use tests to drive the discovery of object interfaces and collaborations.
  • Mock objects help define boundaries between components.
  • Well-designed OO systems are inherently more testable.

Key Books Referenced

For deeper exploration, consult bibliography.md for the full annotated reading list.

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.