I'm practicing my newbie c++ skills by making a small game using SFML and OpenGL. The programming part has been going fine for the most part, but I've questions regarding actual code/class design.
I've one class, MainLoop, which contains the game loop and owns one instance of each of the following classes: Events, Graphics, Commands, Game and UI. I initially wanted all of those to be a single class( with functions separated in different .cpp files), but was told that was the wrong approach for OOP/C++. However, while I can see the good side with separating them( encapsulation, modularity, debugging), I seem to be encountering a lot of bad stuff too. Let me take an example with the user pressing a UI button.
First, the MainLoop gets the event from SFML's window class. MainLoop sends it over to my own Event class, which interprets the event and sends it over to the UI class to check if it 'hit' any of the buttons. If true, the UI class then sends it over to the Command class which interprets the button command. Then, finally, the command class sends it over to the Game class or wherever else it needs to go.
It all seems very heavy-handed to me, and has also, at least the way I've been doing it at the moment, required a lot of forward declarations( and before I learned about those I ended up with tons of circular dependencies). I doubt it does much good for performance either.
Anyway, is there some trick here that I'm missing? How should these classes be connected, how should they communicate? How should I be forwarding commands from, say, the Event class to the UI class? Should I really have forward declarations, includes and stuff everywhere, and doesn't that ruin modularity? Should I have it all run through the MainLoop class and forward the returns using the integers/floats/chars which don't require declarations instead? I'm kinda at a loss here.