I have the following situation in my code and don't know if it reveals some wrong design.
class A
{
public:
...
void estimateParameters(const std::vector<double> &data);
private:
B m_algorithm;
int m_parameter1;
int m_parameter2;
};
void A::estimateParameters(const sdt::vector<double> &data)
{
m_algorithm.estimate(this, data); // And then m_parameter1 and m_parameter2 are filled
}
The implementation of estimateParameters calls the estimate method of B, which receives as parameter a pointer to this. It sounds a little bit strange to me and seems redundant. I am employing this scheme to encapsulate the parameter estimation of A without enforcing the user to manually create an instance of B in his code and then pass A. It is a way to make transparent the parameter estimation to the user.
It is common this type of scheme? Do you think it is the best way to do this? Any alternative less redundant or clearer?
Thank you
Aucun commentaire:
Enregistrer un commentaire