2

いくつかの専門クラスがあります。例えば

class Transition_Matrix : public Transition
{
     SetMatrix(Matrix* pStartMatrix);
};

class Transition_Vector : public Transition
{
     SetVector(Vector* pStartVector);
}

class Transition_Container : public Transition
{

}

設定する必要があるオブジェクトの種類ごとに関数を宣言せずに、Animate_Container で SetVector() または SetMatrix() を呼び出したいと思います。たとえば、次のように Animate_Container を宣言したくありません...

class Transition_Container : public Transition
{
    SetMatrix(Matrix* pStartMatrix);//loops through all children calling SetMatrix
    SetVector(Vector* pStartVector);//loops through all children calling SetVector
}

Animate_Container に、どの子がいるかを知られたくありません。しかし、コンテナーでこれらの関数を呼び出す便利さが必要なので、子を検索して、行列またはベクトルを "遷移" するときにどの関数を呼び出す必要があるかを判断する必要はありません。

ここで使用する正しいパターンは何ですか?

基本的に、ルート コンテナーに行列またはベクトルを設定し、それを使用する可能性がある各子に伝播させたいと考えています。

アイデア?

4

1 に答える 1