私はオンライン記事を読んでいて、 "ヘッドファーストデザインパターン"を読む過程で、 "変化するものをカプセル化する"という基本的なOOPの1つと思われます。私は自分の問題にそれを適用する方法に固執しています、問題を正しい方法で見ていないかもしれないので、私はいくつかのアドバイスを得ることを望んでいました。推定問題にOOPを適用する方法にこだわった
私は自分のアプリケーション、目標、そして私が最後に直面している問題よりも、自分が持っているコードを表示します。コードの一部を省略し、入力を簡略化しました。私はこれが設計上の問題であると考えていたので、すべてのコンストラクタなどを表示する必要はありません。
私のアプリケーションでは、最小二乗法(LS)、拡張カルマンフィルタ(EKF)、逐次最小二乗法(SLS)のような測定器を使用して測定を行い、測定値を処理します。私は、エスティメータが使用されている実行時の変更にしたいと思います。
各推定器には基本的に、推定値に依存して異なるメソッド「更新()」と「DetectBlunders()」(この順序で呼び出されます)がありますが、目的は同じです。だから、もともとは、 "Update()"と "DetectBlunders()"というメソッドを持ち、各エスティメータが "BaseEstimator"から継承した "BaseEstimator"を持っていました。具体的な見積もりを導入することで、私はいくつかの問題を認識し始めました。
1)EXFでは、Update()の前に1つの追加ステップ "Predict()"が必要です。だから私はもともと "BaseEstimator"に "Predict()"メソッドを追加し、LSとSLSで "Predict()"は何もしません。しかし、この種のことは間違っているようです。私が "Predict()"を変更したり、LSの "BaseEstimator"からそれを削除しても、SLSは最初に "Predict()"を持っていなくても影響を受けます。
2)EKFとSLSでは、Update()に1つの余分な入力が必要です。だから前と同じようなことをしました。私は "BaseEstimator"の "Update()"にこの余分な入力を追加しました。そして、私は空の変数を渡すだけです。繰り返しますが、これは間違っています。この入力は別のオブジェクトなので、実際にはLSの空のコンストラクタを渡します。LSではコンストラクタが空の場合はテストが非常に間違っています。
誰でも私が何ができるかについて何かアドバイスがありますか?たぶんこれが問題に近づく唯一の方法です。最終目標は、実行時に見積もりを作成する "EstimatorFactory"(使用するのに十分理解できる唯一の設計原則)を作成することでした。私は将来、「パーティクルフィルタ(PF)」のような他の推定を追加するかもしれません。繰り返しますが、OOPを実際に使用するのは非常に新しく、旧式の私はどこでも/スイッチを使用し、3つの見積もりをすべて1つのクラスにします(数千行後)。
class BaseEstimator {
public:
// I dont actually call my inputs 1,2,3,4
virtual bool Update(
double input1, // Required by all three estimators
double input2, // Required by all three estimators
double input3, // Required by all three estimators
double input4 // Not required in LS, but required in EXF and SLS
);
virtual bool DetectBlunders() const = 0;
// Only required by EXF
virtual bool Predict(
double input1,
double input2
) = 0;
};
class EXF : public BaseEstimator {
public:
bool Update(
double input1,
double input2,
double input3,
double input4);
bool DetectBlunders() const;
bool Predict(
double input1,
double input2);
};
class LS : public BaseEstimator {
public:
bool Update(
double input1,
double input2,
double input3,
double input4 = 0 // This is not needed in LS so I actually pass it an empty constructor
);
bool DetectBlunders() const;
bool Predict(
double input1,
double input2) {
// Do nothing since its not required in LS
}
};
class SLS : public BaseEstimator {
public:
bool Update(
double input1,
double input2,
double input3,
double input4);
bool DetectBlunders() const;
bool Predict(
double input1,
double input2) {
// Do nothing since its not required in SLS
}
};