Inappropriate Intimacy (Subclass Form)


  • A class accesses internal (should-be-private) parts of its parent. (There is a related form of Inappropriate Intimacy between separate classes; see "Inappropriate Intimacy [General Form]," Chapter 10.)


It's natural that parent and child classes be more coupled together than two strangers. Sometimes this just goes too far.

What to Do

  • If the subclass is accessing the parent's fields in an uncontrolled way, use Self Encapsulate Field.

  • If the parent can define a general algorithm that the children can plug into, then use Form Template Method.

  • If the parent and child need to be even more decoupled, then Replace Inheritance with Delegation .


Reduces duplication. Often improves communication. May reduce size.


None identified.

Refactoring Workbook
Refactoring Workbook
ISBN: 0321109295
EAN: 2147483647
Year: 2003
Pages: 146

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: