<分区>
在下面的代码片段中,我从 ReadFile()
函数多次调用了 SetParams()
和 Execute()
。
我可以通过单个调用优化每个 SetParams()
和 Execute()
吗?
bool SubscriptionRead::ReadFile()
{
IVerification* pReader = new FileReader();
std::wstring oemPathPublicKey(oemFolderPath)
, oemPathSessionKey(oemFolderPath)
, oemPathUserChoices(oemFolderPath);
oemPathPublicKey.append(PUBLIC_KEY_FILE);
oemPathSessionKey.append(SESSION_KEY_FILE);
oemPathUserChoices.append(USERCHOICES_FILE);
pReader->SetParams((wchar_t*)oemPathPublicKey.c_str(), L"file");
pReader->Execute();
pReader->SetParams((wchar_t*)oemPathSessionKey.c_str(), L"file");
pReader->Execute();
pReader->SetParams((wchar_t*)oemPathUserChoices.c_str(), L"file");
pReader->Execute();
return True;
}
void FileReader::SetParams(wchar_t* wszParams, wchar_t* wszParamType)
{
m_wszParamType = wszParamType;
m_wszParams = wszParams;
}
bool FileReader::Execute()
{
if (wcscmp(m_wszParamType, L"registry") == 0)
{
function1();
}
else
{
function2();
}
return true;
}