Follow the Principle of Proximity

The principle of proximity focuses on how well organized your code is with respect to readability and change. Proximity implies that functions that are changed together are moved closer together. Proximity is both a design principle and a heuristic for refactoring hotspots toward code that’s easier to understand.

Let’s pretend you run an X-Ray analysis on a large hotspot and as you look at its internal change coupling, you identify several cases of obvious code duplication.

images/patterns/ef_coupling.png

You see an example of such code duplication in the figure, and the gut reaction is to extract the commonalities into a shared abstraction. ...

Get Software Design X-Rays now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.