我正在研究一個非常大的函數中的一些舊代碼,並且我需要編寫一個新函數以便從舊函數中調用幾次。這個新功能將提供有關在舊功能早期是否需要Return
的信息。重構一個可能返回函數的函數
我的問題是什麼是更直接或更好的方式來完成下面的內容?我如何重構這個?
我想另一種方式要問是什麼更好的方式Return
a Return
?
Public Class ExampleClass
''' <summary>
''' This function calls another function
''' </summary>
''' <returns></returns>
Protected Overridable Function FunctionOne() As Boolean
FunctionOne = False
Dim lobjOne, lobjTwo, lobjThree As Object
Dim lblnExit As Boolean = False
'
' Some logic here (manipulates/gets objects)
'
lblnExit = FunctionTwo(lobjOne, lobjTwo)
If lblnExit Then
Return lblnExit
ElseIf lobjOne.This.That > 2 Then
Return lblnExit
End If
'
' Some more logic here (manipulates objects)
'
lblnExit = FunctionTwo(lobjOne, lobjTwo)
If lblnExit Then
Return lblnExit
ElseIf lobjOne.This.That > 2 Then
Return lblnExit
End If
'
' Performing some final actions
'
End Function
''' <summary>
''' This function is called by FunctionOne Multiple Times
''' </summary>
''' <returns></returns>
Protected Overridable Function FunctionTwo(ByVal pobjOne As Object, ByVal pobjTwo As Object) As Boolean
FunctionTwo = False
'
' Performing some long complicated checking that either Returns true or exits
'
End Function
End Class
也許這個問題屬於這裏http://codereview.stackexchange.com/? – HengChin