In my application, it is necessary to register various events occurring in the application. For example, I need to register a file download event from a server and specify the download time, server IP address and so on. Structurally, all this data extends to various classes in the application.
My solution is to create a singleton class, name it, for example, "ApplicationEvents", and handle the application events in it. For example:
void OnFileDownloaded() { ... ApplicationEvents::Instance()->FileDownloaded(fileId_); }
But this seems like a mess in the code and is almost impossible to verify.
An alternative solution would be to create an ApplicationEvent in the main function and pass it to the class constructors as a parameter. To avoid confusion in the code, you can use a decorator or proxy template.
For example: "FileDownloader" and decoration class "LoggingFileDownloader". But the structure of the application will be more complex, many classes will simply pass a pointer to ApplicationEvents through other classes, and this will probably be redundant in my case.
Which solution would be better?
source share