/craft:oop-principlesfrom craft
Guides cross-language OOP design with Tell Don't Ask, collection over named properties, Whole Object pattern, and iterable collections. Activates when designing classes or discussing encapsulation.
Ships in craft. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
The rules below are language-agnostic. Concrete syntax-specific examples live in:
php-oop(PHP —IteratorAggregate, readonly properties)ts-oop(TypeScript —Symbol.iterator, branded types)
These principles focus on patterns where Claude tends to produce "ask" code instead of "tell" code.
The object that owns the data exposes the behavior. Do not extract data to make decisions externally.
Smell: caller queries obj.getX(), applies a condition, then calls back into the object.
Fix: push the condition into the object — expose a method that already encodes the decision (obj.getMissingX(), obj.canDoY()).
Criterion: if the same if/match on object state appears in multiple call sites, the object should own it.
When elements share the same type and undergo the same processing, use an indexed collection — even if the count is known and fixed.
Smell: $frontFile, $backFile, $passportFile (or frontFile, backFile, passportFile) with parallel handling code.
Fix: a single keyed collection (Map<string, File>, array<string, File>) with one loop.
Criterion: same nature + same treatment (upload, validation, display) = collection.
When multiple parameters come from the same object, pass the object. Extracting primitives on the caller side is feature envy.
Smell: add(documentType: doc.type, documentName: doc.originalFileName, downloadUrl: url) — three properties of doc destructured.
Fix: addFromDocument(doc, url) — let the receiver extract what it needs.
Criterion: if a call site reads ≥ 2 properties of the same object to pass them along, pass the object.
When a collection will be iterated, expose iteration without exposing the underlying array. The language provides a protocol for this (PHP: IteratorAggregate, TS: Symbol.iterator, Python: __iter__, …).
Smell: public property holding the underlying array, allowing coll.files.push(...).
Fix: keep the array private, implement the language's iteration protocol so for ... of coll (or equivalent) works.
Criterion: if a caller iterates the collection, it must not be able to mutate it directly.
Include the type / identity in the value object so consumers don't need an external mapping to interpret it.
Smell: { content, originalFileName } + a separate fieldName → fileType mapping kept by the consumer.
Fix: add the type (or other discriminator) inside the value object — { type, content, originalFileName }.
Criterion: if a consumer needs an external lookup to know what kind of value object it received, the type is missing from the object.
| Rule | Principle |
|---|---|
| Tell Don't Ask | The object exposes behavior, not data to interpret |
| Collection > named properties | Same nature + same processing = indexed collection |
| Whole Object | Pass the entire object, not its extracted primitives |
| Iterable + private | Use the language's iteration protocol, keep internals private |
| Self-describing VO | Include type/identity in the object — no external mapping |
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
oop, tell-dont-ask, whole-object, encapsulation, object-design
npx claudepluginhub fabiensalles/claude-marketplace --plugin craft8 skills in this plugin
/code-style-principlesACTIVATE whenever writing or modifying production code in src/, in any language — this is the base layer these rules build on. ACTIVATE for code review, formatting questions, or 'coding standards'. Covers cross-language code style: control-structure spacing, early-return pattern, continue-vs-if/else in loops, explicit (non-truthy/falsy) checks, flattening nested null checks, parameter ordering. These rules go BEYOND standard linters. Language-specific syntax (no-empty in PHP, template literals in TS, nowdoc, optional chaining vs nullsafe) lives in php-code-conventions / ts-code-conventions, which apply on top of this skill rather than instead of it. DO NOT use for: language-specific syntax already covered by php-code-conventions / ts-code-conventions (see php:php-code-conventions + typescript:ts-code-conventions for PHP/TS specifics)./ddd-fp-principlesACTIVATE when modeling DDD aggregates, value objects and domain logic using functional patterns — immutable records, curried operations, Result types, validation/enrichment pipelines, handler orchestration. ACTIVATE for 'aggregate', 'smart constructor', 'make*', 'validation pipeline', 'enrichment', 'domain handler' in a functional context. Provides cross-language functional DDD principles. For OOP-style DDD (classes, decorators, module-bounded contexts) see craft:ddd-principles. Companion examples: ddd-ts-fp.Other plugins' skills for the same job