0

I using C++ to develop a software, and I am confused where to place the ProjectManager.

For example: the project have 4 more module. Each Module is organized by a set of head file and source file. The dependency graph shows like below:

higher level module depends on low level. ModuleBC and Other and depends on A. ModuleOther depends on BC.

                   ModuleOther
  ...                 |
  ...                 |
ModuleB   ModuleC     |
  |           |       |
  |-----------|-------|
  |
ModuleA

The ModuleB and ModuleC have its Manager, ManagerB and ManagerC. A Manager here is a class that deal with static resource init and finialize. It should be init before using class in the module. It should be finalized after using.

For example: If we want using class B1 we must init ManagerB first and finialize ManagerB after use.

At this stage, I want a ProjectManager to manage ManagerB and ManagerC. It is used to manage the static resource in whole project. Init it is equal to init ManagerB and ManagerC.

ProjectManager::init()
{
ManagerB::init();
ManagerC::init();
}

My problem is where should place my ProjectManager? placed in Module A or B or C or any else? How to reduce the dependency? The main function should be used something like follow

int main()
{
ProjectManager::init();

B1 b1;
b1.usingModuleB();
C1 c1;
c1.usingModuleC();
D1 d1;
d1.usingOtherModule();
...

ProjectManager::finialize();
}
Xu Hui
  • 1,213
  • 1
  • 11
  • 24
  • Last time I had problems with a project manager we went out, had a few drinks, and sorted things out. I doubt this solution will be usable in your case. Your case I think comes down to opinion. If I had to do this (and I probably wouldn't. [I'd apply RAII](https://stackoverflow.com/questions/2321511/what-is-meant-by-resource-acquisition-is-initialization-raii) instead) I'd place `ProjectManager` in it's own file down at the root of the source tree where it can happily interact with the other classes without getting in their way. – user4581301 Oct 09 '19 at 03:41
  • @user4581301 Thanks for hint that RAII, I now have the clue. We acutally do not need ProjectManager. We can using the RAII to manager the static resources. And using lazy Singleton Pattern to initalize static resources when we want to use it. – Xu Hui Oct 11 '19 at 10:32
  • Lazy Singleton as in [something like this?](https://stackoverflow.com/a/1008289/4581301) – user4581301 Oct 11 '19 at 18:15
  • @user4581301 yep~ – Xu Hui Oct 13 '19 at 11:37

0 Answers0