这是我使用最多并觉得最有作的重构。有时我们给方法、类或是参数命名时并不能做到见名知义,这样容易引起对代码的误解中,当这种情况发生时,我们可以利用重命名重构来消除这种误解。

     1: public class Person

   2: {
   3:     public string FN { get; set; }
   4:  
   5:     public decimal ClcHrlyPR()
   6:     {
   7:         // code to calculate hourly payrate
   8:         return 0m;
   9:     }
  10: }
 
正像你所看到的,上例中我们给属性、方法提供了一些具有二义性的不能自我描述的名称,通过重命名重构,我们来给上例中的属性和方法提供一个清晰的命名。
   1: // Changed the class name to Employee
   2: public class Employee
   3: {
   4:     public string FirstName { get; set; }
   5:  
   6:     public decimal CalculateHourlyPay()
   7:     {
   8:         // code to calculate hourly payrate
   9:         return 0m;
  10:     }
  11: }
 
原文链接:http://www.lostechies.com/blogs/sean_chambers/archive/2009/08/07/refactoring-day-7-rename-method-class-parameter.aspx

相关文章:

  • 2021-09-18
  • 2021-05-24
  • 2021-12-20
  • 2021-07-13
  • 2021-12-16
  • 2021-06-02
  • 2021-07-29
  • 2021-11-17
猜你喜欢
  • 2021-08-23
  • 2021-08-06
  • 2021-07-26
  • 2021-10-07
  • 2021-12-25
  • 2022-01-17
  • 2022-01-04
相关资源
相似解决方案