方法对比

//修改前
namespace
CleanCSharp.Methods.Dirty { class Utils { public int Process(Customer customer) { if (string.IsNullOrWhiteSpace(customer.FirstName) || string.IsNullOrWhiteSpace(customer.LastName)) { return -1; } else { var service = new CustomerService(); } if (!service.Save(customer)) { return -1; } else { return 1; } } } }
//修改后
namespace
CleanCSharp.Methods.Clean { class Utils { public int Process(Customer customer) { const int customerNotSaved = -1; const int customerSavedSuccessfully = 1; if (!IsValidCustomer(customer)) { return customerNotSaved; } if (!SaveCustomer(customer)) { return customerNotSaved; } return customerSavedSuccessfully; } private bool IsValidCustomer(Customer customer) { if (string.IsNullOrWhiteSpace(customer.FirstName) || string.IsNullOrWhiteSpace(customer.LastName)) { return false; } return true; } private bool SaveCustomer(Customer customer) { var service = new CustomerService(); var successfullySaved = service.Save(customer); return successfullySaved; } } }

 

posted @ 2017-04-07 14:40  小小高  阅读(219)  评论(0编辑  收藏  举报