Inappropriate Intimacy

InappropriateIntimacy is a CodeSmell that describes a method that has too much intimate knowledge of another class or method's inner workings, inner data, etc.

These two methods or classes may be serving the same purpose, the similar parts should be extracted into a separate class using the ExtractClass refactoring.

Maybe the other method needs to be in this class along side the current method: Use MoveMethod.

Maybe the other data needs to be over here with the current method: Use MoveField

Maybe the inner data should be exposed instead of being private: Use EncapsulateField

If it's a subclass method knowing or doing too much with the superclass, either MoveMethod the method into the superclass, or ReplaceInheritanceWithDelegation? (http://www.refactoring.com/catalog/replaceInheritanceWithDelegation.html).


But inappropriate intimacy makes it more exciting! Seriously though, isn't this a restatement of LawOfDemeter? Perhaps the knowledge of the workings of the superclass is new, as in not covered by LawOfDemeter.

Perhaps, but this article was specifically linked from CodeSmell, so I thought it warranted SOMETHING. Also, this code smell is known as InappropriateIntimacy in other circles, so I thought it warranted its own article -- even if we end up nuking everything here and redirecting to LawOfDemeter. Thoughts? -- CMyers

EditText of this page (last edited June 11, 2006) or FindPage with title or text search