I have a series of test that need to run one after another. The previous programmer wrote a giant if else. I've simpified down to a global bool variable that is check at the start of each procedure. Here is the some code snippet.
// Run Luminance Test
RunLuminanceTest(ref failureCode, ref failureDescription);
//Run MSR check
RunMsrCheck(ref failureDescription, ref failureCodes, ref failureCode);
//Run Firmware check
RunFirmwareCheck(ref failureDescription, ref failureCodes, ref failureCode);
//Check Monitor power up
RunMonitorPowerUpCheck(ref failureCodes, ref failureCode);
// Run Power Check
RunPowerCheck(ref failureCodes, ref failureCode);
//Check Video Abnormality
CheckVideoAbnormality(ref failureCodes, ref failureCode);
// Vmi Check
RunVmiCheck(ref failureCodes, ref failureCode);
This is really ugly and prone to have bugs. Is there a design pattern that can I can implemented to make it easy to read and debug? The program is written in C#/Winform.
edit: sorry for the confusing. Prasad telkikar's link is what I'm looking for. I am looking for a design pattern that can replace a giant if else statement.
Aucun commentaire:
Enregistrer un commentaire