Home Knowledge Base Inappropriate intimacy

Inappropriate intimacy is a code smell where two classes or modules have excessive knowledge of each other's internal details — characterized by classes that access private fields, use implementation internals, or have bidirectional dependencies that violate encapsulation principles, making code difficult to modify, test, and maintain independently.

What Is Inappropriate Intimacy?

Why It's a Code Smell

Signs of Inappropriate Intimacy

Direct Symptoms:

Code Patterns:

// Inappropriate intimacy - accessing internals
class Order {
    void applyDiscount() {
        // Accessing Customer's internal pricing data
        double rate = customer.internalPricingData.getBaseRate();
        double tier = customer.loyaltyPoints / customer.POINTS_PER_TIER;
    }
}

// Better - ask, don't grab
class Order {
    void applyDiscount() {
        double discount = customer.calculateDiscountRate();
    }
}

Refactoring Solutions

Move Method/Field:

Extract Class:

Hide Delegate:

Replace Bidirectional with Unidirectional:

Use Interfaces:

AI Detection Approaches

Tools for Detection

Inappropriate intimacy is a maintainability killer — when classes know too much about each other's internals, the codebase becomes fragile and resistant to change, making refactoring to clean boundaries essential for long-term software health.

inappropriate intimacycode smellcouplingencapsulationrefactoringsoftware designcode aicode quality

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.