So previously we had a function like this:
protected void FinalizeImportButton_Click(object sender, EventArgs e) {
if (_IsNotImportStatus(ResponseImport.ImportStatusId, ResponseImportStatusEnum.Imported)) return;
ResponseImportServiceExtended responseImportService = new ResponseImportServiceExtended();
responseImportService.ChangeImportStatus(ImportId, (long)ResponseImportStatusEnum.Finalized);
Navigation.RedirectToUrl(SiteMap.ResponseImports.ImportsList, false);
}
Maybe it could be written a little bit clearer? Today when I see what I wrote, I definetly think so. Let’s see:
protected void FinalizeImportButton_Click(object sender, EventArgs e) {
if (!_IsImportInImportedStatus(ResponseImport)) return;
ServiceLocator<ResponseImportServiceExtended>.ChangeStatusToFinalized(ResponseImport);
Navigation.RedirectToUrl(SiteMap.ResponseImports.ImportsList);
}
What do you think? Would you understand this a little bit easier and quicker?
Ofcourse this approach requires:
a) More customized functions
b) Service Locator
Which in return requires more complicated code, but for the sake of clarity and maintainability (e.g. Instantiating service would be done all in one place…) this would be a smarter approach I think.
Cheers!
Filed under:
Refactoring
Written on: 27 Aug 2007 ·
No Comments »