I'm writing a game.
I'm structuring the game is such a way that theres several "systems" (that derive from ISystem)
Ex: AssetManagementSystem, WindowSystem, etc.
and I think it would be really cool to also have another kind of systems, for debugging.
So my idea is that theres a class: DebugSystem (that derives from ISystem)
and then every system that should only work when debugging is active, derives from that. (as opposed to ISystem)
Ex: DebugLoggerSystem, DebugStatisticsSystem, etc.
My first idea was to have a bool "Debug" in the DebugSystem base class, that i could then set to true and false.
But the thing i dont like about that, is that i then manually have to check this bool in every single debug system
(Ex DebugLoggerSystem's Log function has to check as well as DebugStatisticsSystem's update function)
So I was wondering if there is some sort of clever way to make it so that: if any function of a class that derives from DebugSystem is called then it is simply ignored. (if debugging is disabled)
(So, this way i wont have to manually add code to not execute functions when debugging is disabled in every single debug system)
Using inheritance to add orthogonal functionality is very poorly supported in languages like C++ and Java - languages which have somehow managed to kludge a semblance of object-oriented-programming atop a rigidly static type system.
Composition is a lot more flexible: strongly consider adding orthogonal functionality (like debugging support, thread safety etc.) to objects by run-time composition.
For example, here is an outline sketch (note: this is just a sketch) of this approach: