Alrite. So does this code break the law?
[color="#1C2837"][color="#000088"]void [color="#660066"]PhysicsEngine[color="#666600"]::[color="#660066"]CollideWithWorld[color="#666600"]([color="#000088"]const [color="#660066"]GameCharacter[color="#666600"]&[color="#000000"] gameChar[color="#666600"]) [color="#666600"]{ [color="#880000"]//.... [color="#660066"]BoundingBox[color="#000000"] bBox [color="#666600"]=[color="#000000"] gameChar[color="#666600"].[color="#660066"]GetMeshBoundingBox[color="#666600"](); [color="#000088"]bool[color="#000000"] result [color="#666600"]= [color="#660066"]Collide[color="#666600"]([color="#000000"]bBox[color="#666600"]); [color="#880000"]//..... [color="#666600"]}
Yes.
Instead, the classes should be structured like this:
class GameCharacter {
void CollideWithWorld() {
bool result = world->Collide(bBox); // or bBox.Collide(world);
}
private:
BoundingBox bbox;
World * world;
};
The original code is too small to make any meaningful distinction though, so the above may not seem like a relevant change and World is not defined, so it might be unsuitable abstraction as well.
In practice, very few libraries use such design, especially those concerned with physics, since it represents worst possible design with regard to hardware architecture (aka, slowest possible).