1

I have a factory, GuiTable.cpp where I create multiple GUI-related classes. I also have a database class, CommonStrDatabase.h which serves as a database file for different strings used in the GUI. One of the classes I create in the factory looks like this:

#include "display/DisplayMenu.h"

#include "CommonStrDatabase.h"

namespace gui{
namespace display{

DisplayMenu::DisplayMenu(MenuID Id, MyProcess* OwnerProc)
: Menu(Id, STRING_DIAGMENU, OwnerProc)
{
    Layout layout( paramText,
                   paramTop,
                   paramWidth,
                   setParamtHeight );

    int row = 0;
    layout.addGraphicalControl(row++, 0, new StrView(DEV, OwnerProc, "Close menu" , 0, 0, TEXTALIGN_L, TextFont));

...
}

The parameter STRING_DIAGMENU is a string(actually a typedef but does not matter here) which comes from CommonStrDatabase.h. My question: is it better to include the database file as I did here, or would you include it in the factory, and then pass the string as a parameter to the DisplayMenu, like this:

#include "display/DisplayMenu.h"
#include <string>

namespace gui{
namespace display{

DisplayMenu::DisplayMenu(MenuID Id, MyProcess* OwnerProc, string DiagMenuString)
: Menu(Id, DiagMenuString, OwnerProc)
{
    Layout layout( paramText,
                   paramTop,
                   paramWidth,
                   setParamtHeight );

    int row = 0;
    layout.addGraphicalControl(row++, 0, new StrView(DEV, OwnerProc, "Close menu" , 0, 0, TEXTALIGN_L, TextFont));

...
}

I suppose it is better to include the database file in one place, in the factory, otherwise you would have to include it in every class which uses it? Will multiple includes make the compilation time slower, even if you use #pragma once in CommonStrDatabase.h?

4
  • Welcome ! If I understand your question correctly, you want to know more about how to cope with multiple header dependencies. Unfortunately, coding issues are out of scope here. I’d recommend that you close it and first search for existing answers to similar questions on stackoverflow. If you do not find anything ask the question there.
    – Christophe
    Dec 11 '19 at 7:47
  • The funny thing is that I first posted the question here: stackoverflow.com/questions/59275087/… But I was told that the Software Engineering page is more appropriate for this question :)
    – Wballer3
    Dec 11 '19 at 8:57
  • @Christophe I think this question fits for this portal as the OP is asking for suggestions regarding coding guidelines and styling.
    – Sisir
    Dec 11 '19 at 9:37
  • @Sisir Is this a software engineering question ? Isn’t this rather about how to write good code in c++ ?
    – Christophe
    Dec 11 '19 at 11:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.