mercredi 20 octobre 2021

C++ git submodules with common interface

Let's say I have a main "core" C++ git project called Core. Inside this Core project, somewhere, I want to have some polymorphic container of objects. Something like std::vector<std::unique_ptr<Module>>, where Module is a C++ interface (with pure virtual methods). I then have classes inheriting from Module and implementing all the pure virtual Module methods. Let's call these ModuleA and ModuleB (class ModuleA: public Module, etc.).

Now let's suppose the classes ModuleA and ModuleB are not implemented just in one .h and one .cpp file, but have many helper classes and functions associated to them, in many other files. Now, is it possible to somehow put ModuleA and ModuleB in their own git projects? I am aware of git submodules, but how can I achieve common interface in ModuleA and ModuleB? Both of them would need to "see" the Module interface, which is defined in the Core git project, but that project includes ModuleA and ModuleB, so that is a circular dependency problem.

I was thinking about using C++ templates for this, but none of my template solutions were "clean" enough. Is there any solution to this? Or is this a terrible design pattern in general?

Aucun commentaire:

Enregistrer un commentaire