ライブラリに、ユーザーに公開したいクラスがあります。後でバイナリ互換性のない変更を行う可能性があるため、クラス全体を公開したくありません。次の方法のどれが最適かについて混乱しています。
ケース 1:
struct Impl1;
struct Handle1
{
// The definition will not be inline and will be defined in a C file
// Showing here for simplicity
void interface()
{
static_cast<Impl1*>(this)->interface();
}
}
struct Impl1 : public Handle1
{
void interface(){ /* Do ***actual*** work */ }
private:
int _data; // And other private data
};
ケース 2:
struct Impl2
struct Handle2
{
// Constructor/destructor to manage impl
void interface() // Will not be inline as above.
{
_impl->interface();
}
private:
Impl2* _impl;
}
struct Impl2
{
void interface(){ /* Do ***actual*** work */ }
private:
int _data; // And other private data
};
Handleクラスは、機能を公開するためだけのものです。ライブラリ内でのみ作成および管理されます。継承は、実装の詳細を抽象化するためのものです。複数の/異なるimplクラスはありません。性能的にはどちらも同じだと思います。それは...ですか?ケース1のアプローチで行くことを考えています。対処する必要がある問題はありますか?