I have the following existing classes:
class Gaussian {
public:
virtual Vector get_mean() = 0;
virtual Matrix get_covariance() = 0;
virtual double calculate_likelihood(Vector &data) = 0;
};
class Diagonal_Gaussian : public Gaussian {
public:
virtual Vector get_mean();
virtual Matrix get_covariance();
virtual double calculate_likelihood(Vector &data);
private:
Vector m_mean;
Vector m_covariance;
};
class FullCov_Gaussian : public Gaussian {
public:
virtual Vector get_mean();
virtual Matrix get_covariance();
virtual double calculate_likelihood(Vector &data);
private:
Vector m_mean;
Matrix m_covariance;
};
As you can see, the Gaussian class acts as an interface, but has no implementation. It all works fine.
Now I want to create the "AdaptedGaussian" class, where the data vector provided to the calculated likelihood will be changed before the probability is calculated.
Some requirements:
- AdaptedGaussian must be a child of the Gaussian class
- AdaptedGaussian should be able to "wrap" or "be an instance" of all possible Gaussian classes
- AdaptedGaussian must be built from an existing Gaussian object
Now I have an idea:
class Adapted_Gaussian : public Gaussian {
private:
Gaussian* m_g;
public:
virtual Vector get_mean() { return m_g->get_mean(); }
virtual Matrix get_covariance() { return m_g->get_covariance(); }
virtual double calculate_likelihood(Vector &data)
{
return g->calculate_likelihood(Vector &data);
}
}
There may be some disadvantages:
- For each method (and here more than shown here) in the new class
- ,
- - , , .
? ?
m_g?