I have many modules (C++ classes) that use a common class (HW_util)
HW_util class actually initializes the Hardware.
All the modules are initialized with the address of HW_util object. I have 30+ modules and so 30 odd lines that just do the initialization and I find this code ugly. Is there a better way to do this?
class HW_Util
{
InitHW();
Functionality1_onHW();
Functionality2_onHW();
..
CleanupHW();
};
class Module1
{
Module1(HW_Util *util) { m_Util = util; }
..
HW_Util *m_Util;
void DoSomething()
{
//uses m_Util to do something
}
};
class Module2
{
Module2(HW_Util *util) { m_Util = util; }
..
HW_Util *m_Util;
void DoSomething()
{
//uses m_Util to do something
}
};
...
//I have around 30 such modules..
...
void main()
{
HW_Util util;
Module1 mod1(&util); //I am passing util to all these modules, and I have around 30 such modules, ugly code
Module1 mod1(&util);
Module3 mod1(&util);
Module4 mod1(&util);
Module5 mod1(&util);
util.InitHW(); //actually fill up the util
mod1.DoSomething();
mod2.DoSomething();
..
util.CleanupHW();
}
Aucun commentaire:
Enregistrer un commentaire