If you have a static (global) instance of any class (s), it can be accessed from anywhere in the world, and it can turn out to be a "big ball of dirt", making it difficult to keep track of what it uses or needs.
One idea of the so-called "SOLID" principles is that
"Details must depend on abstractions."
Currently, introducing additional abstract base classes (or interfaces in languages that support them) may seem complicated, but it can help you find which parts of each object you need, where you want it from, and let you introduce another Game in the future.
One approach might look like this:
#include <iostream> class World { public: int Info() { return 0; } }; //An abstract base class class IGame { public: virtual ~IGame() = 0 {} virtual int FPS() = 0; }; //One specific type of game class Game : public IGame { public: int FPS() { return 0; } }; class Camera { public: Camera(Game * game, World * world) : game(game), world(world) { } void Move() { //actually move first then ... Draw(); } void Draw() { //This will show us what needs to be public in the other classes std::cout << world->Info() << '\n'; if (game) std::cout << game->FPS() << '\n'; } private: IGame* game; World* world; }; int main() { World world; Game game; Camera camera(&game, &world); camera.Move(); }
(to the principle of dependency inversion), as discussed in this question
It may seem redundant for what you are doing, but it brings you closer to "everything depends on something abstract," and not on "everything that depends on everything else."
source share