← CodeClarityLab Home
Browse by Category
+ added · updated 7d
← Back to glossary

Refused Bequest

quality Intermediate

Also Known As

refused inheritance refused bequest smell

TL;DR

A subclass that inherits methods it doesn't need or want, signalling a misused inheritance relationship.

Explanation

Refused Bequest is a code smell where a subclass inherits behaviour from a parent but overrides it to do nothing, throws an exception, or simply ignores it. This is a strong signal that the inheritance hierarchy doesn't reflect a genuine is-a relationship. The fix depends on severity: if the subclass reuses some parent behaviour, extract a sibling class from the parent; if it shares no meaningful behaviour with the parent, replace inheritance with composition. The Liskov Substitution Principle is violated whenever a subclass refuses part of its parent's contract.

Common Misconception

Refused bequest is fixed by moving the unwanted methods to the subclass. The signal is that the subclass should not extend this parent at all — the fix is usually composition rather than inheritance, where the class takes only what it actually needs.

Why It Matters

When a subclass ignores most of its inherited interface, the inheritance relationship is wrong — the subclass should not extend the parent, or the hierarchy needs splitting.

Common Mistakes

  • Subclasses that throw UnsupportedOperationException for inherited methods — the interface contract is broken.
  • Empty method overrides that silence inherited behaviour — the inheritance is wrong, not the method.
  • Using inheritance for code reuse when composition would not impose the unwanted interface.
  • Not using interfaces to define capability subsets — implement only what applies rather than inheriting everything.

Code Examples

✗ Vulnerable
// Child refuses to use methods inherited from parent
class ReadOnlyList extends ArrayList {
    public function add(\$item): void {
        throw new \RuntimeException('Read-only list cannot be modified');
    }
    public function remove(\$item): void {
        throw new \RuntimeException('Read-only list cannot be modified');
    }
}
✓ Fixed
// Fix: don't inherit what you can't use — use composition or a separate interface
interface ReadableList {
    public function get(int \$index): mixed;
    public function count(): int;
}

class ReadOnlyList implements ReadableList {
    public function __construct(private array \$items) {}
    public function get(int \$index): mixed { return \$this->items[\$index]; }
    public function count(): int { return count(\$this->items); }
    // No add/remove — they simply don't exist here
}

Added 15 Mar 2026
Edited 22 Mar 2026
Views 18
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 1 ping S 0 pings M 0 pings T 1 ping W 2 pings T 0 pings F 2 pings S 1 ping S 0 pings M 0 pings T 1 ping W 0 pings T 0 pings F 1 ping S 0 pings S 0 pings M 0 pings T 0 pings W 1 ping T 0 pings F 0 pings S
No pings yet today
No pings yesterday
Amazonbot 8 Google 4 Perplexity 2 Unknown AI 2 ChatGPT 2 Ahrefs 1
crawler 15 crawler_json 4
DEV INTEL Tools & Severity
🟡 Medium ⚙ Fix effort: High
⚡ Quick Fix
When a subclass ignores or throws on inherited methods, use composition instead — extract the shared code to a collaborator and inject it rather than inheriting it
📦 Applies To
any web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
Subclass throwing UnsupportedOperationException on inherited methods; override returning null or empty for parent method that should do something
Auto-detectable: ✗ No phpstan psalm
⚠ Related Problems
🤖 AI Agent
Confidence: Medium False Positives: High ✗ Manual fix Fix: High Context: Class Tests: Update

✓ schema.org compliant