Is this a good class hierarchy for my project
(this is also in comp.object group, but because it includes C++ and MFC code
also I put it here as well)
Lets say I have a weather data application to design. I have data and then I
will draw it on windows.
This is how I was thinking to implement it:
Base-Classes: Data, Chart (to draw data on window), DataAnalysis (includes
all functions to analyze the data and create corresponding values to draw
info on chart)
Then we can inherit different weathers from these, like "Finnish weather" ,
"USA weather", "Moon weather", "globe weather" etc.
So the final result/class hierarchy would look like this (my question below
them) for USA Weather (for example):
// Data
class WeatherData
{
....
}
// classes for analysing data
class WeatherAnalysis
{
protected:
WeatherData m_Data; // data to analyze
void SetData(...);
WeatherData& GetData();
void DoSpecialAnalyze();
virtual void DrawDifferentMark();
....
}
// class for USA weather
class USAWeatherAnalysis : public WeatherAnalysis
{
....
}
// data drawing
// CView is a windows class in Microsoft C++ MFC foundation classes to draw
to windows
class ChartView : public CView
{
private:
WeatherData* m_pData; // a pointer to data to draw
protected:
virtual void DrawDifferentMark(int i);
public:
void SetWeatherData(WeatherData* pData) { m_pData=pData; }
....
}
// Then finally the class which hold everything together and links data to
windows view
class USAWeatherAnalysisView : public ChartView, public USAWeatherAnalysis
{
public:
void ReadUSAWeatherDataFromFile();
virtual void DrawDifferentMark();
}
Now we can read and set the data:
void USAWeatherAnalysisView ::ReadUSAWeatherDataFromFile()
{
// reading data from file to WeatherData object
WeatherData data;
....
// Then storing the data to WeatherData m_Data -member:
SetData(data);
//Then passing pointer of this data to the other parent class ChartView:
SetWeatherData(&GetData());
}
Now lets say we analyze data on WeatherAnalysis:
void WeatherAnalysis::DoSpecialAnalyze()
{
for(eath data-item)
{
if(data item is different than other items)
DrawDifferentMark(item);
....
}
}
So we have a virtual function DrawDifferentMark in WeatherAnalysis:
class WeatherAnalysis
{
....
virtual void DrawDifferentMark(int item);.
....
}
When DrawDifferentMark is called it goes to USAWeatherAnalysisView version,
and from there we can call the corresponding drawing class method:
void USAWeatherAnalysisView ::DrawDifferentMark(int item)
{
ChartView::DrawDifferentMark(item);
}
So item pass route is: WeatherAnalysis -> USAWeatherAnalysisView ->
ChartView
Is this a good way to implement the communication between data and
view/drawing windows? This way also if something happens in windows and we
want to communicate that to data classes (or analyzing classes), then we can
similarly create a virtual function in Chart class and route it via
USAWeatherAnalysisView to analysis/data classes
(ChartView ->USAWeatherAnalysisView-> WeatherAnalysis ).
This is how I was thinking of doing it, but if anyone can tell if this is
the best way before I start would be nice :).
And if you give advices, can you please write corresponding code...
otherwise its difficult for me to understand it.