City Metaphor

The City Metaphor is a powerful way to visualize software code as a 3D city. It’s especially useful for understanding large, complex object-oriented codebases by mapping code elements to city-like structures.

In this metaphor:

  • Buildings represent types like classes, interfaces, structs, enums, etc

  • Building height corresponds to the size or complexity of the class (e.g. lines of code, number of methods)  or other class-level metrics

  • Building width/depth can represent the number of attributes or other class-level metrics

  • City blocks or districts represent packages, modules, or namespaces.

 

TODO Bild einfügen

 

What It’s Good For

  • Cognitive Aid: Our brains process spatial metaphors well. You can "walk through" the codebase like exploring a city.

  • Detecting Smells: Unusually large or complex classes (like "skyscrapers") or overpopulated packages (like "slums") visually stand out.

  • Architecture Overview: Helps identify cohesion, coupling, and structural anomalies.

 

Example Analogy

Imagine your software is a city:

  • A package becomes a district.
  • Each class is a building in that district.
  • A huge building (class with thousands of lines) might indicate a God Object or low cohesion.
  • Dense blocks might indicate tight coupling or poor modularization.