毕业论文论文范文课程设计实践报告法律论文英语论文教学论文医学论文农学论文艺术论文行政论文管理论文计算机安全
您现在的位置: 毕业论文 >> 英语论文 >> 正文

软件工程Visual Studio 2005实现VB重构英文文献及翻译 第2页

更新时间:2010-11-18:  来源:毕业论文
软件工程Visual Studio 2005实现VB重构英文文献及翻译 第2页
A reconstruction instance is called encapsulate field. Encapsulate field means making fields become private and restricting accession to these fields through public properties. The access restricted for the object is superior to the one unlimited. Encapsulate field is based on believing the value of restricted access for the data(some people maybe disagree the basic premise-the constrained access has an advantage over free access, others still think that there are not some good points based on object to design, let alone the issue about disputing whether reconstruction is optimum or not. However, the article assumes the optimum reconstruction.)
Encapsulate field’s idea lies in the belief-public data is the worst. In order to finish encapsulate field, make a public field become private one and read the present private fields values by the adding accessor method. In VB.NET, the getter and setter actually are just some convenient method symbols-allow you to treat a field’s property from outside when calling methods. These field mean that you can carry out the package check for them.
Supposed that you have a named HeartRate public field and it can adjust one patient every other minute. The bad code probably will set up HeartRate 500 and like what Emeril said, “cheating” the patient is dead. In order to prevent setting the HeartRate too high, you can use property method to protect it. You can use mouse right clicking the HeartRate field to select “Refactor” then choose “encapsulate field”. You will see the operations in the IDE similar to these. After that, you will use the downward arrow to move selector(red arrows and threads) until the insert point and press the return key. The modified th code looks like the list 1
The list 1:HeartRate field is encapsulated by Refactor
Imports System.ServiceProcess
Public Class WillRefactor
Private HeartRate As Integer
Public Property HeartRate1() As Integer
Get
Return HeartRate
End Get
Set(ByVal value As Integer)
HeartRate = value
End Set
End Property
End Class
For the modified codes in the list 1, if you don’t use public property HeartRate1, you won’t change the HeartRate. In order to avoid setting the HeartRate too high, you can add somme extra codes in the Set method.
• 4   reconstruction: extract method
the most common problem in the coding, funcation is too long. Small funcations can be reused and more easily rearranged in the new behavior. Under the general circumstance, the funcation with long code are only used for the strictest restriction condition. In order to reuse code easily, you can extract code fragment to form some naming methods. Apart from these naming methods which should be reuse easily, the name also clearly explain the method’s purpose. In order to use extract method, choose a code fragment which you want to convert into a name method, then right click mouse on the selected 原文请找腾讯752018766辣-文^论-文.网http://www.751com.cn times to console. If you only have one available reconstruction, you can use reconstruction of a button-press the Ctrl+~,it can activate the reconstruction and show a action hint. Another time, move the selector up and down in its current position then press the return key. After pressing the key, the PseudoLongMethod and the newly extracted method will be modified. For details, see the list 2.
The list 2: the PseudoLongMethos is reconstructed, which makes BunchOfcode become an independent method.
      
       Imports System.ServiceProcess
Public Class WillRefactor
Private HeartRate As Integer
Public Property HeartRate1() As Integer
Get
Return HeartRate
End Get
Set(ByVal value As Integer)
HeartRate = value
End Set
End Property
Public Sub PseudoLongMethod()
' a bunch of code
BunchOfCode()
End Sub
Private Sub BunchOfCode()
Dim I As Integer
For I = 1 To 100
Console.WriteLine(HeartRate)
Next
End Sub
End Class
•  5   reconstruction: create overloading
Provided that BunchOfCode’s defination is accepting a Count parameter(Count is used for the loop’s ceiling limit value), and have known a default value in some circumstances. You can right click BunchOfCode(see list 3)and select “Refactor!| Create Overload” to create a new method which can overload BunchOfCode and call the primitive by a default value.(see the list 4)
The list 3: new code version having a single parameter
          Private Sub BunchOfCode(ByVal count As Integer)
Dim I As Integer
For I = 1 To count
Console.WriteLine(HeartRate)
Next
End Sub
          The list 4: the new and old overloading BunchOfCode method created by Refactor:         
Private Sub BunchOfCode(ByVal count As Integer)
Dim I As Integer
For I = 1 To count
Console.WriteLine(HeartRate)

上一页  [1] [2] [3] 下一页

软件工程Visual Studio 2005实现VB重构英文文献及翻译 第2页下载如图片无法显示或论文不完整,请联系qq752018766
设为首页 | 联系站长 | 友情链接 | 网站地图 |

copyright©751com.cn 辣文论文网 严禁转载
如果本毕业论文网损害了您的利益或者侵犯了您的权利,请及时联系,我们一定会及时改正。