I'd like to design a robust version of this class (C++11):
class Oscillator
{
private:
std::vector<double> trajectory_;
// Some numbers that are needed to get the trajectory
double xinit_;
double vinit_;
double omega_;
public:
Oscillator(double xinit, double vinit, double omega):
xinit_(xinit), vinit_(vinit), omega_(omega) {}
void Integrate(); // Implementation populates 'trajectory_'
// Implementation prints the trajectory in JSON-friendly format
void PrintJSON(std::ostream &);
double TrajectoryMean();
double TrajectoryStdv();
};
Here are some thoughts:
- I'd like to replace the
PrintJSON
method with a private variable of classTrajectoryPrinter
or something, so that I don't have to changeOscillator::PrintJSON
and recompileoscillator.cpp
everytime there's a problem - The same goes for the
TrajectoryMean
member. I'd rather have a classTrajectoryStats
that does this for me.
The only problem with the above points is this: both proposed classes require access to a private member of Oscillator
: trajectory_
.
Is there a design pattern or generic design solution to this problem? Is what I am asking for possible?
Thanks.