Code Smell Inappropriate Intimacy
Signs and Symptoms
One class uses the internal fields and methods of another class.
Reasons for the Problem
Keep a close eye on classes that spend too much time together. Good classes should know as little about each other as possible. Such classes are easier to maintain and reuse.
- The simplest solution is to use Move Method and Move Field to move parts of one class to the class in which those parts are used. But this works only if the first class truly does not need these parts.
If the classes are mutually interdependent, you should use Change Bidirectional Association to Unidirectional.
If this "intimacy" is between a subclass and the superclass, consider Replace Delegation with Inheritance.
- Improves code organization.
- Simplifies support and code reuse.
Tired of reading?
No wonder, there are 7 hours worth of the text on this website.
Try our interactive course on refactoring. It offers less boring approach to learning new stuff.Let's see...