State with namespaces and locals - or classes?

Now the modules in my game engine are organized as namespaces. They have the functions Open () and Close (), which act similarly to the constructors and destructors of classes and are called when the game is entered to the left.

Examples of such modules are: a physical manager, an object manager, an I / O handler, and a rendering manager.

Now I'm starting to think that it is bad to have all the variables of the modules "lying" around and exported globally through the linker.

Refactoring modules from namespaces to classes will result in the following overhead:

  • There should be a global controller that allows you to interact between different modules, proving access to their instances

  • The interaction between the modules would get additional overhead for calling the function and 1-2 pointer markups

And the following benefits:

  • RAII approval
  • All state can be packed into one CState class, which contains instances of modules
  • Good to make sure resources are removed and properly distributed.

My questions:

  • Should I consider reorganizing my module modules from namespaces to managed classes? Why not)?
+3
source share
2 answers

If you have a set of functions (methods) that work with a collection of objects that should not be visible to other functions outside this set, then, naturally, it would be to put this set of functions and objects in a class.

, ,

? - "-". , , , , .

1-2

, . , , , .

+4

, , , .

:

  • , . .

  • . - .

  • , PIMPL. . PIMPL - .

, - , , , . - , . , , ++ .

  • , .
0

Source: https://habr.com/ru/post/1794906/


All Articles