C ++ output: GUI or console?

I am making a C ++ application that runs a simulation for a health club. The user simply enters the simulation data at the beginning (3 integer values) and starts pressing. After that there is no user input - it's that simple.

After starting the simulation, most of the logic is in the deep lower class, but many of them have to print simple output messages in the user interface. It is not possible to return a message because objects must print in the user interface, but continue to work.

I was going to pass a reference to the user interface object for all the classes that need it, but I end up passing it quite a lot - there should be a better way.

What I really need is what can make calling the printOutput (string) function of the user interface simpler (or not much more complicated) than cout <<string

The user interface also has a displayConnectionStatus (bool []) method.

Remember that the user interface inherits from the abstract class UserInterface, so the simple and simple console user interfaces and graphical interfaces can be easily changed.

How do you suggest me to implement this link in the user interface?

If I used a global function, how can I redirect it to the methods of invoking the UserInterface implementation that I chose to use?

+4
source share
2 answers

Do not be afraid of globals.

Global objects damage encapsulation, but for a targeted solution that does not require immediate reuse, global variables are just fine.

Output a global object that processes events from your simulation. You can then print the events, send them an email, make them using OpenGL, or whatever you like. Make a single interface that will catch what's happening inside the simulation using report callbacks, and then you can subclass this global object according to your needs.

If the object was not global, you should pass a pointer around the entire code base.

+4
source

I would suggest going to the registration framework, i.e. your own LogMessages class, which received functions that receive data and register data, it can be a user interface, a file, a network, or something else.

And every class that needs logging can use your logging class.

This way you can avoid global and common solutions, as well as take a look at http://www.pantheios.org/ , which is an open source C / C ++ Diagnostic Logging API, you can use this as well ...

0
source

All Articles