#include <iostream>
#include <windows.h>
using namespace std;
/************************************************************************/
/* 模板模式:定义一个操作中的骨架,将一些延迟操作放到子类中
/* 模板模式使子类可以不改变一个算法的骨架即可重定义该算法中的某些特定的步骤
/************************************************************************/
class CalcSNR
{
public:
CalcSNR()
{
}
void GetSNRValue()
{
GetRawData();
GetBaseData();
double dSNR = StartCalcSNR();
cout << "SNR Value:" << dSNR << endl;
}
virtual void GetRawData() = 0;
virtual void GetBaseData() = 0;
virtual double StartCalcSNR() = 0;
};
class SNRAlogrithm : public CalcSNR
{
public:
virtual void GetRawData()
{
//throw std::logic_error("The method or operation is not implemented.");
cout << "Get Raw Data"<<endl;
}
virtual void GetBaseData()
{
///throw std::logic_error("The method or operation is not implemented.");
cout << "Get Base Data"<<endl;
}
virtual double StartCalcSNR()
{
//throw std::logic_error("The method or operation is not implemented.");
cout << "Start Calc SNR"<<endl;
return 0.1;
}
};
int main(int argc, char *argv[])
{
CalcSNR *pCalcSNR = new SNRAlogrithm();
pCalcSNR->GetSNRValue();
getchar();
}
template model
最新推荐文章于 2022-08-24 10:50:46 发布