DEV Community

loading...
Cover image for Code Smell 64 - Inappropriate Intimacy

Code Smell 64 - Inappropriate Intimacy

Maxi Contieri
Learn something new every day. - I am a senior software engineer working in industry, teaching and writing on software design, SOLID principles, DDD and TDD.
・1 min read

Code Smell 64 - Inappropriate Intimacy

*Two classes entangled in love.

Problems

  • Coupling

  • Bad Responsibilities Assignments

  • Bad Cohesion

  • Class Interfaces too Public

  • Maintainability

  • Extensibility

Solutions

  1. Refactor

  2. Merge

  3. Replace Hierarchy With Delegation.

Sample Code

Wrong

Right

Detection

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

Tags

  • Coupling

Conclusion

It 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

More info

C2 Wiki

Refactoring Guru

Codebuzz

Credits

Photo by Becca Tapert on Unsplash


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

Robert Martin

Discussion (0)