您创建类的目的之一是将所有不相关的数据和操作分离到不同的类。
在您的情况下,一部分是计算,另一部分是结果布局。
因此,实现它的最佳方法是定义一个提供所有计算和访问结果的类,并实现绘图功能,该功能将使用您的计算类的对象。
因此,它可以在其他环境(例如,在您的其他项目中)使用您的计算,而无需更改任何代码,这是很自然的。它将提供与平台无关的计算代码的可移植性。
而布局部分,依赖于平台,应该单独实现,只使用计算类提供的接口。
class Trajectory
{
public:
// Constructor, computation call methods
// "GetResult()" function,
// which will return trajectory in the way you choose
...
private:
// computation functions
};
// somewhere else
void DrawTrajectory(Trajectory t)
{
// here is a place for calling all winapi functions
// with data you get using t.GetResult()
}
如果需要抽象类,你应该从抽象类继承 Trajectory 类,
您将在其中定义必须调用的所有函数。
在这种情况下
//
class ITrajectory
{
public:
// virtual /type/ GetResult() = 0;
// virtual /other methods/
};
class Trajectory : public ITrajectory
{
// the same as in previous definition
};
void DrawTrajectory(ITrajectory T)
{
// the same as in previous definition
}