# Code Smell 64 - Inappropriate Intimacy

# Problems

*   Coupling
    
*   Bad Responsibilities Assignments
    
*   Bad Cohesion
    
*   Class Interfaces too Public
    
*   Maintainability
    
*   Extensibility
    

# Solutions

1.  Refactor
    
2.  Merge
    
3.  Replace Hierarchy With Delegation.
    

%[https://refactoring.com/catalog/replaceSuperclassWithDelegate.html] 

# Sample Code

## Wrong

%[https://gist.github.com/mcsee/5f9206a8a131b4dcaaa2fd64562c9eca] 

## Right

%[https://gist.github.com/mcsee/f94d51d327592ca511b625bac37cb441] 

# Detection

Some linters graph class relations and protocol dependency. Analyzing the collaboration graph we can infer rules and hints.

# Tags

*   Coupling
    

# Conclusion

If two classes are too related and don't talk much to others we might need to split, merge or refactor them, Classes should know as little about each other as possible.

# Relations

%[https://maximilianocontieri.com/code-smell-63-feature-envy] 

# More info

%[https://wiki.c2.com/?InappropriateIntimacy] 

%[https://refactoring.guru/es/smells/inappropriate-intimacy] 

%[https://www.thecodebuzz.com/awesome-code-inappropriate-intimacy-code-smell-resolution/] 

# Credits

Photo by [Becca Tapert](https://unsplash.com/@beccatapert) on [Unsplash](https://unsplash.com/s/photos/intimate)

* * *

> No matter how slow you are writing clean code, you will always be slower if you make a mess.

*Robert Martin*

* * *

%[https://mcsee.hashnode.dev/software-engineering-great-quotes] 

* * *

This article is part of the CodeSmell Series.

%[https://mcsee.hashnode.dev/how-to-find-the-stinky-parts-of-your-code]
