Alternative to "#ifdef" parties to suppress a call to a specific class

I am redistributing an application in which the graphical interface and the external interface are strongly connected to each other, mainly because a certain class MainGuiis called everywhere to refresh the screen or show a specific message, for example

getMainGui()->refreshDisplay()
getMainGui()->beginUpdate()
getMainGui()->showMessage()

Because of this, some modules are not tested without a GUI. We need to create a command line executable that can be used for testing.

I want to make these no-op calls on the command line. The most obvious approach is to simply protect calls with #ifdef, but there are hundreds of links ... I would like to make the changes as localized as possible. Any thoughts?

ps: I can change MainGuiandgetMainGui()

+3
4

MainGui? :

getMainGui()

MainGuiMock, getMainGui() ifdef, , .

[]

, getMainGui(), , , , , . MainGui MainGuiMock.

, .exe, GUI-. , [edit], singe exe, .

0

- . , refreshDisplay. TestGui, ,

0

GUI-: , ( ) , .

, GUI, getMainGui() . GUI, .

++:

class animal {
  public:
    virtual void make_sound() = 0;
};

class dog : public animal {
  void make_sound() { cout << "woof!" << endl; }
};

class null_animal : public animal {
  void make_sound() { }
};
0

, , , "" , . - , , , , ( get/set, //CPU/etc). , , , , (, ) - ).

, :

  • if the application code itself is a template type (or reasonable for templates), you can provide a GUI class type to use as a template parameter

  • if the application code uses the main GUI file of the static / anonymous namespace in its implementation file, you can #ifdefsimply replace this line with the test version

(if you post more of your actual code, it would be easier to make specific recommendations, since a lot depends on what appears in the headers, stand-alone and class members, etc.)

0
source

All Articles