26.7.13

Inappropriate Intimacy

Just realize that my understanding of Inappropriate Intimacy was incorrect. I thought if many classes were coupled to used a specific class, it is inappropriate intimacy. However, this is not.

Inappropriate Intimacy means one class is implemented upon the details of another class.

In Refactoring the book:


  • Sometimes classes become far too intimate and spend too much time delving in each other's private parts.
  • We may not be prudes when it comes to people, but we think our classes should follow strict, puritan rules.
This is how the name came from. 

By reading the book again, I find that I really like the language of the book. I used to read the Chinese version, but the English version is better.

  • Move method/move field
  • Change Bidirectional Association to Unidirectional
  • Extract class
  • Hide Delegate
    • Hide Delegate
    • The example in the book of "Hide Delegate" is very intuitive. You can create a delegation method getManager() for Person, instead exposing its Department (private part) for accessing his manager. 
  • Replace Delegation with Inheritance. (I think this should be: replace inheritance with delegation)

No comments: