liveBook · Manning

Interface bloat

As explained in Grokking Software Architecture

Interface bloat is an interface design problem in which one interface combines excessive or unrelated operations that force clients to depend on methods they do not need.

Interface bloat occurs when one interface bundles unrelated operations, forcing clients to implement methods they do not need. A midfielder shouldn’t have to promise goalie skills: that contract creates useless methods, confusing code, and coupling to changes outside the client’s needs. section 3.4.4

The midfielder with goalie drills

A bloated training interface might require a midfielder to implement diving saves and hand distribution, perhaps by throwing errors. Separating operations by role leaves the midfielder with relevant drills and gives goalie-specific methods to the goalie. section 3.4.4

Listing 3.10 “After”: Following ISP
class Midfielder {
    practiceShooting() { /* ... */ }
    practiceTackling() { /* ... */ }
}
 
class Goalie {
    practiceShooting() { /* ... */ }
    practiceTackling() { /* ... */ }
    practiceDivingSaves() { /* ... */ }
    practiceHandDistribution() { /* ... */ }
}

Compare the position-specific method sets: midfielders keep shooting and tackling, while goalkeepers also have goalie-specific operations. section 3.4.4

How Grokking Software Architecture covers it

How deep it goes
Defines the failure through forced methods and placeholder errors, then contrasts it with role-specific operations.
Examples
Uses soccer training to show a midfielder forced to implement goalie drills and a role-specific alternative.
What you can do after
Evaluate interfaces for irrelevant operations and separate methods around the client roles that need them.
How it connects
Connects interface bloat to the Interface Segregation Principle, coupling, and maintainability.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Software Architecture. The section links point to the parts of the book it draws on.