For a long time now, I have used used this very informative article by Scott Meyers when implementing interfaces and functions:
http://drdobbs.com/cpp/184401197
However, I basically need some opinions on what is best for my current task.
I am writing a collection of functions that will perform calculations on data. These functions share a common theme, however they do not share state, so as of now I have them grouped in a namespace:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
namespace StatsAnalysis
{
DLLDIR double CalcThis(
DocMap &dm,
const int searchType,
const int searchVal_1,
const int searchVal_2
)
{
RawData data;
switch (searchType)
{
case TYPE1: data = SearchByDocumentID(searchVal_1, searchVal_2, dm); break;
case TYPE2: data = SearchByDocumentType(...); break;
case TYPE3: data = SearchByDocumentStatus(...); break;
//perform specific calculation and return
}
DLLDIR double CalcThat(
DocMap &dm,
const int searchType,
const int searchVal_1,
const int searchVal_2
);
}
| |
Each one calls one of three helper functions to retrieve the data from supplied from the DocMap, and then performs a specific calculation related to the function name. Each calculation function performs the same switch case to retrieve data.
As said earlier, they do not share any common state, so they are not in a class. The only reason I can think of to put them in a class is so that the result from searching the data can be cached, if more than one calculation is required for the same data set.
Is this a good approach? I think its better than having to call methods to change the data, search type and parameters, and then the calculation, but I do not know.
Any help is appreciated. Thank you.