gpt4 book ai didi

c++ - 共享对象加载器的设计问题

转载 作者:行者123 更新时间:2023-11-28 08:26:32 24 4
gpt4 key购买 nike

我一直在开发此类以应用程序的共享对象形式加载插件。我目前想到了两种加载应用程序要加载的所有插件的文件名的方法。我写了一个加载文件名的接口(interface)。我有几个关于如何改进这个设计的问题。请帮忙。谢谢。

编辑:根据反馈更改代码 :D。

#include "Plugin.h"

//This class is an interface for loading the list of file names of shared objects.
//Could be by loading all filienames in a dir, or by loading filenames specified in a file.
class FileNameLoader
{
public:
virtual std::list<std::string>& LoadFileNames() = 0;
};

class PluginLoader
{
public:
explicit PluginLoader(LoadingMethod, const std::string& = "");
virtual ~PluginLoader();

virtual bool Load();

virtual bool LoadPlugins(FileNameLoader&);
virtual bool LoadFunctions();

protected:
private:
explicit PluginLoader(const PluginLoader&);
PluginLoader& operator=(const PluginLoader&);

bool LoadSharedObjects();

list<std::string> l_FileNames;
list<PluginFunction*> l_Functions;
list<Plugin*> l_Plugins;
};

还有什么看起来很丑陋的吗?无论如何,感谢您的反馈。

最佳答案

在我看来,您的功能分布在 enumFileNameLoaderPluginLoader 类中。

我的建议是制作一个 PluginLoaderByFile 类和一个 PluginLoaderByDir 类 - 一个可以继承另一个,或者可以有一个公共(public)基类。通过这种方式,您可以定义其他子类,包括必要的附加代码,并在必要时将其封装起来。

这也使它更容易使用,例如factorybuilder future 的模式。

关于c++ - 共享对象加载器的设计问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3913617/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com