我有一個具有顯式類模板特化和另一個部分類模板特化的類模板。如何從不同的實現中分離一個類
template< typename T1, typename T2 >
class A{
internal_representation1 inRep;
// methods
};
template<>
class A < specific_type_1,specific_type_2 >{
//internal represenation different for this type.
internal_representation2 inRep;
// methods
};
template< template T1 >
class A < T1,specific_type_2 >{
//internal represenation different for this type.
internal_representation3 inRep;
// methods
};
專業化會導致界面重複。類模板及其特化都具有相同的方法名稱,但它們的實現有所不同。具體而言,它們的內部數據結構的表示方式不同。
我應該用橋接設計模式替換上述實現嗎?
注:這個問題是有關How can we implement the Builder design pattern using boost::mpl?
internal_representation的完全不同嗎? –
是的,一個是'std :: vector',第二個是'boost :: dynamic_bitset',第三個是'ComplexUDT'。這些類型是目前支持的類型,將來代碼可能需要支持更多。因此,將接口與實施分開很重要。 –
你有一個**模板**和兩個顯式實例。模板是**不是**類。 –