oop-composition-over-inheritance

oop-composition-over-inheritance is a skill for Claude Code from helmedeiros/clean-code-skills. It costs 48 tokens per session (745 once invoked), scanned A, original, MIT.

An object-oriented programming guide for combining small, independent behaviors instead of building deep class inheritance trees.

In plain words
What is it for?
Choosing composition when designing classes, especially when inheritance hierarchies are deep, rigid, or difficult to extend.
Why use it?
It helps avoid tightly connected classes where changes to a parent class unexpectedly affect many child classes.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin.

Part of the clean-code-skills plugin — 21 skills, 2 commands shipped together

Good fit Choosing composition when designing classes, especially when inheritance hierarchies are deep, rigid, or difficult to extend.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/helmedeiros/clean-code-skills/oop-composition-over-inheritance
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add helmedeiros/clean-code-skills --skill oop-composition-over-inheritance
Clone the repo
git clone --depth 1 https://github.com/helmedeiros/clean-code-skills

Made for: Claude Code.

Or install clean-code-skills, the plugin that ships this one along with the rest of its 21 skills, 2 commands.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for oop-composition-over-inheritance

README.md
[![agentmods](https://agentmods.dev/badge/skills/helmedeiros/clean-code-skills/oop-composition-over-inheritance/github.svg)](https://agentmods.dev/skills/helmedeiros/clean-code-skills/oop-composition-over-inheritance)
Your own site
<a href="https://agentmods.dev/skills/helmedeiros/clean-code-skills/oop-composition-over-inheritance"><img src="https://agentmods.dev/badge/skills/helmedeiros/clean-code-skills/oop-composition-over-inheritance/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for oop-composition-over-inheritance

Your own site · 80×15
<a href="https://agentmods.dev/skills/helmedeiros/clean-code-skills/oop-composition-over-inheritance"><img src="https://agentmods.dev/badge/skills/helmedeiros/clean-code-skills/oop-composition-over-inheritance.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 48 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 745 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00048 $0.00745
Opus 5.5 $0.00019 $0.00298
Sonnet 5.5 $0.00010 $0.00149
Haiku 4.5 $0.00005 $0.00075

Measured 3mo ago against content hash a513a2cd33fe, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

oop-composition-over-inheritance scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/oop-composition-over-inheritance/SKILL.md · 80 lines

How it starts

The opening of the file, as written. The whole thing — 80 lines — stays where its author put it; the contents beside it link to each section on GitHub.

OOP: Composition Over Inheritance

Favor object composition over class inheritance to achieve flexible, loosely coupled designs that combine behaviors without creating fragile hierarchies.

When This Skill Applies

  • An inheritance hierarchy is deeper than 2-3 levels
  • Subclasses override many parent methods or use only a fraction of inherited behavior
  • A class needs to combine behaviors from multiple sources (multiple inheritance pressure)
  • The user mentions composition over inheritance or the fragile base class problem
  • Changing a base class breaks unexpected subclasses

Core Principle

Inheritance creates tight coupling between parent and child classes. Changes to the base class ripple through the entire hierarchy, often in unexpected ways (fragile base class problem). Composition assembles behavior from independent, interchangeable parts. Prefer "has-a" relationships over "is-a" relationships unless the is-a relationship is genuinely stable and permanent.

Workflow

Step 1: Identify the Hierarchy Problem

Check if the inheritance tree is deep (more than 2-3 levels), wide (many subclasses overriding different behaviors), or rigid (need to combine behaviors in ways the hierarchy does not support).

Step 2: Identify the Behaviors

List the distinct behaviors that vary across the hierarchy. Each behavior is a candidate for a separate component or strategy.

Step 3: Extract Behaviors into Components

Create a class or interface for each behavior. Move the behavior logic from the base class or subclass into the component.

Step 4: Compose at Runtime

The original class holds references to behavior components. Inject them via the constructor. Different combinations of components produce different behaviors without new subclasses.

Step 5: Verify

Ensure the composed behaviors work together. Run the test suite. Confirm that new behavior combinations do not require new classes.

Detection / Indicators

  • Inheritance depth greater than 3 levels
  • Subclasses that override most parent methods
  • "Diamond problem" or desire for multiple inheritance
  • Subclasses that use only a fraction of the parent's API
  • Combinatorial explosion of subclasses: FastRedCar, SlowRedCar, FastBlueCar...
  • Base class changes unexpectedly break distant subclasses

Read the full file on GitHub · 80 lines

Files

What ships with it

1 file beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3mo ago First seen · 80 lines · 48 tokens per session scan A a513a2cd33fe

Subscribe to this mod's changes

oop-composition-over-inheritance is a skill published in the GitHub repository helmedeiros/clean-code-skills (3 stars, last pushed 9mo ago), licensed MIT. It adds 48 tokens to every session and 745 once invoked, about $0.0002 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

oop-composition-over-inheritance compared with skills from other repositories

oop-composition-over-inheritance next to 6 skills from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
oop-composition-over-inheritancehelmedeiros/clean-code-skillsSkill39mo agoMITA48Claude Code
fp-briefsd0xdev/sd0x-harnessSkill1965d agoMITA77Claude Code
codex-explainsd0xdev/sd0x-harnessSkill1965d agoMITA56Claude Code
sharingansd0xdev/sd0x-harnessSkill1965d agoMITB87Claude Code
gan-zhong-xuely8427/gan-zhong-xueSkill12yesterdayMITA288Claude Code
creating-explainersanalyticalmonk/explain-thisSkill231mo agoMITA98Claude Code, Codex
explaining-codebasesanalyticalmonk/explain-thisSkill231mo agoMITA84Claude Code, Codex