# Decide Composition

> When to use Trait+Interface vs Abstract Class. The art of mixing behaviors.

- Skill: `attac-t/decide-composition` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add attac-t/decide-composition`
- Raw SKILL.md: https://api.skillmd.com/api/skills/attac-t/decide-composition/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: attac-t (https://skillmd.com/u/attac-t)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/attac-t/decide-composition

---


# Skill: Composition

> "Favor composition over inheritance."

## The Decision

**Use Trait + Interface when:**
- Behavior crosses inheritance hierarchies
- Multiple behaviors need mixing
- No clear IS-A relationship
- You want horizontal reuse

**Use Abstract Class when:**
- Clear parent-child relationship exists
- Significant shared implementation
- Template method pattern needed
- You want vertical inheritance

## The Heuristic

Ask: *"Does this class **have** this behavior, or **is it** this thing?"*

- **Has** → Trait
- **Is** → Abstract Class

## The Quick Test

| Ask Yourself | Answer | Use |
|--------------|--------|-----|
| Does every subclass need this? | Yes | Abstract |
| Can multiple unrelated classes need this? | Yes | Trait |
| Is there a clear IS-A relationship? | Yes | Abstract |
| Is this a capability/feature? | Yes | Trait |

## Real-World Examples

For concrete examples from Laravel, Spatie, and production code, see [examples.md](examples.md).

