Some might not think it's worth asking but I consider good function names quite important. I am not sure what should be the overridable function name in what I think is template design pattern. I am printing a report which has 3 types. There are lots of ifif
-elseelse
which is confusing. I replace the long function with the polymorphic class hierarchy with base class below. I have than derived a class from each report type which overrides the PrintCustom()
function but this doesn't strike me as a good name to me!.
class CPrintReport
{
protected:
CPrintReport(void);
public:
virtual ~CPrintReport(void);
// template function?
void PrintReport();
protected:
void PrintCommon();
virtual void PrintCustom() = 0;
virtual void PrintChart();
protected:
CStringArray pstrData;
CGraphCtrl * m_GraphCtrl;
};
PrintReport
is the main function which is as following:
void CPrintReport::PrintReport()
{
// prints thte common data
PrintCommon();
// prints specialized (verification,identification or regular type)
PrintCustom();
PrintChart();
}
Does this implement the template design pattern where
PrintReport()
is the template function?As you can see from report, the first section prints common information, and the last section prints a chart, but the middle section varies based on what type of report it is. If it was procedural programming I would be calling this
PrintVerificationData()
andPrintIdentifcationData()
depending on which type of report is being printed. How do we name such methods in the template design pattern so it makes better sense?It turns out
PrintChart
is going to be different as well for each type. However, it is the same for 2 types (verification and identification) and different for regular print. Does this meanPrintChartVerifyIdentify()
(being lazy but making a point) should reside in the base class so it can be shared, or should I use a visitor pattern or something?
Update
I want to add another question since its based on the same information. It turns out PrintChart
is going to be different as well for each type however it is same for 2 types (verification and identification) and different for regular print. Does this mean PrintChartVerifyIdentify()
(being lazy but making a point) should reside in the base class so it can be shared or should use visitor pattern or something?