Course contentsShow
← Software Engineering
Lesson 343 of 1,93310. RefactoringFree lesson

Couplers: Feature Envy and Inappropriate Intimacy

Recognizing when methods are too interested in other classes' data or when classes know too much about each other.

Couplers: Feature Envy and Inappropriate Intimacy

What you'll learn: How to spot when methods and classes are too entangled with each other's internal details, violating proper boundaries.

What Are Couplers?

Couplers are code smells that indicate excessive dependencies between classes. Two common coupler smells are Feature Envy and Inappropriate Intimacy.

Feature Envy

Feature Envy occurs when a method seems more interested in another class's data than its own. The method constantly accesses or manipulates data from a different class, suggesting it might belong there instead.

Analogy: Imagine you're constantly reaching into your neighbor's toolbox instead of using your own tools. Maybe those tools should be in your garage.

Signs of Feature Envy:

  • A method calls many getters on another object
  • A method performs calculations primarily using another class's data
  • The method would be simpler if it lived in the other class

Inappropriate Intimacy

Inappropriate Intimacy happens when two classes know too much about each other's internal workings. They're excessively coupled, making changes in one class ripple into the other.

Analogy: Two coworkers who can't function independently—every decision requires checking with the other, slowing everything down.

Signs of Inappropriate Intimacy:

  • Classes access each other's private fields or methods
  • Classes have bidirectional dependencies
  • Changes in one class frequently require changes in the other
  • Classes share too many implementation details

Why This Matters

Both smells violate encapsulation and increase coupling. They make code harder to understand, test, and modify. The solution often involves moving methods closer to the data they use or introducing proper abstractions to reduce inter-class knowledge.

Key Takeaway: Methods should primarily work with their own class's data, and classes should maintain clear boundaries—Feature Envy and Inappropriate Intimacy signal violations of these principles that increase maintenance burden.