I need some advice on how to refactor the code below. I have multiple configurations classes they are all different, but as you can see in the example code below there is a recurring pattern happening.
I was wondering what would be the best approach to simplify the View code?
class IConfiguration
{
public:
virtual bool Save(const std::string& Output) = 0;
virtual bool OutText(const std::string& BaseFileName) = 0;
}
class MockConfiguration
{
MOCK_METHOD1(Save,bool(const std::string& Output));
MOCK_METHOD1(OutText, bool(const std::string& BaseFileName));
}
void View::SaveConfiguration1(std::string path)
{
m_Configuration1->Save(path);
m_Configuration1->OutText(wxFileName::StripExtension(path).ToStdString())
//Enable Reset Menu
wxMenuItem* item2 = GetMenuBar()->FindItem(wxID_RESET);
if (item2 != NULL) item2->Enable(true);
}
void View::SaveConfiguration2(std::string path)
{
m_Configuration2->Save(path);
m_Configuration2->OutText(wxFileName::StripExtension(path).ToStdString());
//Enable Reset Menu
wxMenuItem* item2 = GetMenuBar()->FindItem(wxID_RESET);
if (item2 != NULL) item2->Enable(true);
}
void View::SaveConfiguration3(std::string path)
{
m_Configuration3->Save(path);
m_Configuration3->OutText(wxFileName::StripExtension(path).ToStdString());
//Enable Reset Menu
wxMenuItem* item2 = GetMenuBar()->FindItem(wxID_RESET);
if (item2 != NULL) item2->Enable(true);
}
Aucun commentaire:
Enregistrer un commentaire