I have a setup of a class that represents a building. This building has a floor plan, which has bounds.
The way I have it setup is like this:
public struct Bounds {} // AABB bounding box stuff
//Floor contains bounds and mesh data to update textures etc
//internal since only building should have direct access to it no one else
internal class Floor {
private Bounds bounds; // private only floor has access to
}
//a building that has a floor (among other stats)
public class Building{ // the object that has a floor
Floor floor;
}
These objects have their own unique reasons to exist as they do different things. However there is one situation, where I want to get a point locally to the building.
In this situation I am essentially doing:
Building.GetLocalPoint(worldPoint);
This then has:
public Vector3 GetLocalPoint(Vector3 worldPoint){
return floor.GetLocalPoint(worldPoint);
}
Which leads to this function in my Floor
object:
internal Vector3 GetLocalPoint(Vector3 worldPoint){
return bounds.GetLocalPoint(worldPoint);
}
And then of course the bounds object actually does the math required.
As you can see these functions are pretty redundant as they just pass on to another function lower down. This doesn't feel smart to me - it smells like bad code thats going to bite me in butt some where down the line with code mess.
Alternatively I write my code like below but I have to expose more to public which I kinda don't want to do:
building.floor.bounds.GetLocalPoint(worldPoint);
This also starts to get a bit silly when you go to many nested objects and leads to large rabbit holes to get your given function and you may end up forgetting where it is - which also smells like bad code design.
What is the correct way to design all this?
"Functions that simply call another function"
That's a wrapper function, e.g., see en.wikipedia.org/wiki/Wrapper_function And they can be very sensibly used, so not necessarily a"bad design choice"
at all.