by Geoff Cox

Software Craftsman. Guitarist. Folk Hero.

Organize Code by Locality of Reference

Organizing class members by access modifier (public, protected, private)or by member type (properties, methods, events) in modern languages are antiquated practices.

Organizing code to match memory layout or header/implementation grouping constraints is a holdover from C/C++ that isn’t necessary today. Unfortunately a couple of tools (I’m looking at you StyleCop) want to enforce these rules in C#.

The Principle of Locality

The principle of locality (referred to as the locality of reference to distinguish it from the physics principle) says:

This directly affects how developers should group class members:

If one class member is referenced, then it is likely that related class members will be referenced in the near future.