クラス Parameter があります。その目的は、特定のパラメーターが保持できる可能性のある値を表すことです (GetNumValues() と GetValue(int index) の 2 つの主要なメソッドを実装します)。
多くの場合、1 つの論理パラメーター (パラメーター値はビット フラグ) は、パラメーター クラスの 2 つ以上のインスタンス (つまり、1 または 2 のパラメーターと、4 または 8 のパラメーター) によって最適に表現されます。 5、6、9、または 10)。これを処理するには、パラメーターを含む CompositeParameter クラスを作成し、保持するパラメーターの組み合わせに基づいて GetNumValues() および GetValue() 関数を実装します。
また、CompositeParameter はパラメーターを組み合わせて 1 つのパラメーターとして機能させるため、「CompositeParameter はパラメーターである」という関係は理にかなっています。そのため、継承元のクラスのオブジェクトを構成するクラスがあるという状況に陥っていますが、これは正しくないようです。しかし同時に、より高いレベルのコードが CompositeParameters と Parameters をまったく同じに扱うことができない理由がわかりません。
私が考えることができる唯一のオプションは、CompositeParameter に単純にパラメーターを構成させることであり、より高いレベルのコードは CompositeParameters のみを処理します。ただし、これはやや無駄です。一般的なケースは、パラメーターを 1 つだけ含む CompositeParameters です。
考え?
class Parameter
{
public:
virtual unsigned int GetNumValues() const {...}
virtual unsigned int GetValue(unsigned int index) const {...}
}
class CompositeParameter : public Parameter
{
public:
// product of GetNumValues() of each item in mParamList
virtual unsigned int GetNumValues() const {...}
// allow all the possible combinations of the items in mParamList to be
// treated as one parameter. i.e. if mNumParams = 2, this would be analogous
// to getting the row and col index of a matrix from index, and combining
// the mParamList[0]->GetValue(row) and mParamList[1]->GetValue(col)
virtual unsigned int GetValue(unsigned int index) const {...}
private:
static const unsigned int MAX_PARAMS = 10;
unsigned int mNumParams;
const Parameter* mParamList[MAX_PARAMS];
}