User interface customization template
I have a Win32 C ++ program that validates user input and updates the interface with state and parameters information. It is currently written like this:
void ShowError() {
SetIcon(kError);
SetMessageString("There was an error");
HideButton(kButton1);
HideButton(kButton2);
ShowButton(kButton3);
}
void ShowSuccess() {
SetIcon(kError);
std::String statusText (GetStatusText());
SetMessageString(statusText);
HideButton(kButton1);
HideButton(kButton2);
ShowButton(kButton3);
}
// plus several more methods to update the UI using similar mechanisms
I don't like this because it duplicates the code and forces me to update multiple methods if something changes in the UI.
I am wondering if there is a design pattern or best practice to remove duplication and make it easier to understand and update features.
I could consolidate the code inside a config function and pass flags to enable / disable UI elements, but I'm not sure if this is the best approach.
Any suggestions and ideas?
+2
a source to share
1 answer