A
away
If there are several equipments of the same type, but made by different
companies, and they are used for the same purpose, measuring temperature,
moisture, etc.
By "the same type" it means that their functionalities are very similar to
each other:
int ReadTemperature();
int ReadMoisture();
....
So far I see two options of designing classes for it:
Option 1:
Design a base class with:
virtual int ReadTemperature();
virtual int ReadMoisture();
....
Then derive each equipment from each company as a derived class.
Option 2:
Use template...
Can anyone point out what're advantages and disadvantages of either option?
Besides the two options above is there any other way to design the case?
In general, when should use template and when better use inheritance?
Thanks!
companies, and they are used for the same purpose, measuring temperature,
moisture, etc.
By "the same type" it means that their functionalities are very similar to
each other:
int ReadTemperature();
int ReadMoisture();
....
So far I see two options of designing classes for it:
Option 1:
Design a base class with:
virtual int ReadTemperature();
virtual int ReadMoisture();
....
Then derive each equipment from each company as a derived class.
Option 2:
Use template...
Can anyone point out what're advantages and disadvantages of either option?
Besides the two options above is there any other way to design the case?
In general, when should use template and when better use inheritance?
Thanks!