C++ Output: GUI or Console? -
i making application in c++ runs simulation health club. user enters simulation data @ beginning (3 integer values) , presses run. after there no user input - simple.
after starting simulation lot of logic deep down in lower classes lot of them need print simple output messages ui. returning message not possible objects need print ui keep working.
i going pass reference ui object classes need end passing around quite lot - there must better way.
what need can make calling ui's printoutput(string) function easy (or not more difficult) cout << string;
the ui has displayconnectionstatus(bool[] connections) method.
bear in mind ui inherits abstract 'userinterface' class simple console uis , guis can changed in , out easily.
how suggest implement link ui?
if use global function, how can redirect call methods of userinterface implementation selected use?
don't afraid of globals.
global objects hurt encapsulation, targeted solution no concern immediate reusability, globals fine.
expose global object processes events simulation. can choose print events, send them e-mail, render them opengl or whatever fancy. make uniform interface catches happens inside simulation via report callbacks, , can subclass global object suit needs.
if object wasn't global, you'd passing pointer around codebase.
Comments
Post a Comment