Should we organize classes based on locality rather than conceptually?
Hypothetically, suppose we write a program to simulate a real-world environment which has three objects: a car, road and tree. Conventional OOP design suggests to conceptually separate these 3 separate classes.
But suppose the car and road objects do millions of calculations among their class member data and methods. Could we improve performance by jumbling the Car and Road into a CarRoad class due to locality of reference? Or if that example is too absurd, if we had another separate Wheel class, which is closely related to a Car, should we jumble the Car and Wheel classes together if their class members interact very frequently?
I wouldn't decide that unless I really profile two different version and compare the performance.
Otherwise I'd like to try a couple of things like, 1. Would it make more sense if one of the other class has template parameter and pass it, instantiating it in compile time. 2. Put one class in another class but inline all of its methods, and also force it(there's compiler flag /attribute to actually force it..) to see if the generated binary has somewhat different locality.
Just random idea..