Refused Bequest
Refactoring & Technical Debt

Meaning

A code smell where a subclass does not use the behavior inherited from its superclass, often overriding a method to throw an exception or return a default, indicating that inheritance is inappropriate.

Primary Function

Signals a design smell where inheritance is misused, suggesting that composition or delegation may be more appropriate.

Communicative Purpose

Alerts developers to reconsider the inheritance hierarchy and consider refactoring to reduce unnecessary inheritance.

Pattern

Subclass overrides a parent method but does not use the inherited behavior (e.g., throws UnsupportedOperationException).

Core Structure

class SubClass extends SuperClass { @Override void method() { throw new UnsupportedOperationException(); } }

Função primária

Signals a design smell where inheritance is misused, suggesting that composition or delegation may be more appropriate.

Propósito comunicativo

Alerts developers to reconsider the inheritance hierarchy and consider refactoring to reduce unnecessary inheritance.

Situações de gatilho

When a subclass overrides a method from its superclass but does not invoke the superclass implementation, instead throwing an exception, returning a default, or providing an empty implementation.

Contextos

Object-oriented programming, inheritance hierarchies, code reviews, refactoring sessions.

Padrão

Subclass overrides a parent method but does not use the inherited behavior (e.g., throws UnsupportedOperationException).

Estrutura central

class SubClass extends SuperClass { @Override void method() { throw new UnsupportedOperationException(); } }

Slots de substituição

SubClass SuperClass method

Colocados típicos

  • subclass superclass override super inheritance

Substituições comuns

  • Inheritance misuse
  • Unused inheritance
  • Subclass ignores parent behavior
  • Override to throw exception

Erros comuns

Using inheritance for code reuse when the subclass does not need the parent's behavior. Confusing Refused Bequest with Lazy Class.

Similar / contraste

Alternative Classes with Different Interfaces (subclass uses parent but adds behavior), Lazy Class (class does little).

Interferências

Do not confuse with 'Lazy Class' where a class does little; Refused Bequest specifically concerns unused inherited behavior.

Família do chunk

  • Alternative Classes with Different Interfaces
  • Lazy Class
  • Data Clumps

Nuance

Indicates that the subclass may not need the parent at all; composition may be a better fit.

Efeito pragmático

Signals a design smell that suggests refactoring to improve design clarity and maintainability.

Dica de memória

Child refusing a gift from parent.

Nota

Refused Bequest indicates that the subclass does not need the superclass's contract; refactor by extracting an interface or using composition to avoid unnecessary inheritance.

Upgrade path

Replace Inheritance with Delegation (refactoring)

Frequência: HighFormulaicidade: FlexibleTipo de construção: lexical_bundlePrioridade de aquisição: Recognition firstPrioridade de output: InputTag de espaçamento: Medium-term

Log in to save chunks.