I have the following problem.
I got a class PluginLoader
which oversees loading of plugins. It divides sub-stages of work to other classes like Plugin
. Plugin
calls functions of PluginLoader
in its processing. Let's call that function AddData
. Here, PluginLoader
has to check if the data it receives is duplicate. For that, it uses a ConflictResolver
class. Now, my problem is how to make an object of ConflictResolver
available to PluginLoader
. There are 3 ways I see out of this.
- Use a
ConflictResolverFactory
class and create an object ofConflictResolver
forPluginLoader
. - Pass a constructed
ConflictResolver*
to thePluginLoader
via its constructor or a member functionSetConflictResolver
and store it in a member variable and use it later. Both ways have drawbacks. If I pass it in the constructor, I will have to throw if the pointer isNULL
. And I can't use exceptions as it is the custom here. If I pass it viaSetConflictResolver
, there is no way that I can guarantee that that function will be actually called by the user. Or I will have to check whether the memberConflictResolver*
isNULL
everywhere I use it. - Pass a
ConflictResolver &
toPluginLoader
sLoad
method where all the work will be done. In turn,Plugin
s Load method has to accept aConflictResolver &
as well (though it has no use for it) and pass that back toAddData
wherePluginLoader
will be able to use it.
Third method is safer compared to second. However, I have to pass around a reference even when it is not used.
If the first method cannot be used, what is the best way to do this?
Apologies for the wall :wq!