In software architecture, modifying an interface to gain access to internal fields can lead to technical debt by creating public contracts that other developers rely on. This can increase the surface area of a class and compromise encapsulation. Specifically, when a class like ImportantService contains private details needed by a single client, such as a migration tool or diagnostic utility, exposing these details through the public interface is tempting but harmful in the long run. A recommended technique is to use closures to maintain internal access without bloating the interface.
Every extension to an interface creates a new public contract. And public contracts are sticky. Other developers start to rely on it. The internal detail becomes external behavior.
Using closures can provide internal access without exposing internal state, and without bloating your interface. This approach preserves encapsulation, keeps dependencies clean, and minimizes ripple effects.
Collection
[
|
...
]