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
