jeudi 30 juin 2016

C++ hierarchical class inheritance design

Suppose that I have the following application logic:

class classA
{
    classA(ConfigA config)
};

class classB
{
     classB(ConfigB config)
};

class App
{
    void initial(Config config){
        if( cond1)
            new classA(config.getConfigA());
        if( cond2)
            new classB(config.getConfigB());
     }
};

Is there good pattern to design the Config structure? Currently what I am doing is

struct BConfig
{
     int a;
     int b;
};

struct ConfigA:public BConfig
{
     int c;
};
struct ConfigB:public BConfig
{
     int d;
};
struct Config
{
    ConfigA getConfigA();
    ConfigB getConfigB();
    int a;
    int b;
    int c;
    int d;
};

I guess there is better way to do it. Any suggestion?

Aucun commentaire:

Enregistrer un commentaire