在我的公司系统中,我们使用一个类来表示bean。它只是使用boost :: variant和一些序列化/反序列化的信息的持有者。它运行良好,但我们遇到了一个问题:它不在接口之上,并且由于我们通过dll使用模块化,为它构建接口变得非常复杂,因为它几乎被应用程序的每个部分所使用,并且可悲地接口(抽象类)必须通过指针访问,巫婆几乎不可能重构整个系统。Turn class“Interfaceable”
我们的结构是:
DLL答:通过抽象类
DLL接口B定义:接口实现
有一种无痛的方式来实现这一目标(可能使用模板,我不知道)或者我应该忘记做这个工作,并简单地链接所有与DLL B?
谢谢
编辑:这是我的例子。
这是在dll上A
BeanProtocol是N dataprotocol itens的持有者,它由索引处理。
class DataProtocol;
class UTILS_EXPORT BeanProtocol
{
public:
virtual DataProtocol& get(const unsigned int ) const
{
throw std::runtime_error("Not implemented");
}
virtual void getFields(std::list<unsigned int>&) const
{
throw std::runtime_error("Not implemented");
}
virtual DataProtocol& operator[](const unsigned int)
{
throw std::runtime_error("Not implemented");
}
virtual DataProtocol& operator[](const unsigned int) const
{
throw std::runtime_error("Not implemented");
}
virtual void fromString(const std::string&)
{
throw std::runtime_error("Not implemented");
}
virtual std::string toString() const
{
throw std::runtime_error("Not implemented");
}
virtual void fromBinary(const std::string&)
{
throw std::runtime_error("Not implemented");
}
virtual std::string toBinary() const
{
throw std::runtime_error("Not implemented");
}
virtual BeanProtocol& operator=(const BeanProtocol&)
{
throw std::runtime_error("Not implemented");
}
virtual bool operator==(const BeanProtocol&) const
{
throw std::runtime_error("Not implemented");
}
virtual bool operator!=(const BeanProtocol&) const
{
throw std::runtime_error("Not implemented");
}
virtual bool operator==(const char*) const
{
throw std::runtime_error("Not implemented");
}
virtual bool hasKey(unsigned int field) const
{
throw std::runtime_error("Not implemented");
}
};
其他类(名为GenericBean)实现它。这是我发现这个工作的唯一方法,但是现在我想将它转换为一个真正的接口并删除UTILS_EXPORT(这是一个_declspec宏),最后删除B与A的强制关联。
你可以添加一些示例代码?真的很难判断你的问题到底是什么。 – 2009-12-28 16:23:21
我不明白,一个抽象类的DLL?没有代码。 – 2009-12-28 16:30:53
为什么使用异常而不是纯虚拟方法? – 2010-01-06 05:20:28