Skip to main content
edited tags
Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237
deleted 70 characters in body; edited title
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

How to name Naming a template print method properly so it makes better sense?

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();

}
  1. Does this implement the template design pattern where PrintReport() is the template function?

  2. 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()and PrintIdentifcationData() 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?

  3. 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 mean PrintChartVerifyIdentify() (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?

How to name template method properly so it makes better sense?

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 if-else 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 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();

}
  1. Does this implement the template design pattern where PrintReport() is the template function?

  2. 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()and PrintIdentifcationData() 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?

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?

Naming a template print method properly

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 if-else 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.

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();

}
  1. Does this implement the template design pattern where PrintReport() is the template function?

  2. 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()and PrintIdentifcationData() 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?

  3. 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 mean PrintChartVerifyIdentify() (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?

added 434 characters in body
Source Link
zadane
  • 337
  • 2
  • 11

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 if-else 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 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();

}
  1. Does this implement the template design pattern where PrintReport() is the template function?

  2. 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()and PrintIdentifcationData() 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?

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?

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 if-else 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 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();

}
  1. Does this implement the template design pattern where PrintReport() is the template function?

  2. 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()and PrintIdentifcationData() 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?

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 if-else 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 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();

}
  1. Does this implement the template design pattern where PrintReport() is the template function?

  2. 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()and PrintIdentifcationData() 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?

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?

deleted 39 characters in body
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237
Loading
edited tags
Link
RubberDuck
  • 30.9k
  • 6
  • 71
  • 174
Loading
added 32 characters in body
Source Link
zadane
  • 337
  • 2
  • 11
Loading
Improved grammar, fixed a few typos.
Source Link
Jerry Coffin
  • 33.6k
  • 4
  • 75
  • 143
Loading
Source Link
zadane
  • 337
  • 2
  • 11
Loading