我有一個項目向其他項目提供服務,並且提供此服務的方法的返回值是String。在該項目中,我使用了一些指定的常量來表示特殊的帶外值,這些值是代替預期的或可恢復的錯誤而返回的,否則服務將返回一個XML字符串。我應該如何讓多個項目之間保持一致?
類似以下內容:
' modService.bas
const SERVICE_BADARG as String = "Unsupported argument."
const SERVICE_TOOMANY as String = "Too many Foos."
' cServiceProvider.cls
Private Function GetXMLString() as String
' generate and return XML string holding all sorts of generic stuff
End Function
Public Function PerformService(argument as String) as String
' do some stuff
If (some_condition = true) Then
PerformService = SERVICE_BADARG
Else If (some_other_condition = true) Then
PerformService = SERVICE_TOOMANY
Else
PerformService = GetXMLString()
我希望能夠從其他項目中,能夠獲得這些常量沒有冗餘定義它們。如果可能的話,我也想避免將它們放在課堂上(不必要地複製它們),並避免爲每個人製作財產。
他們都是常數,他們都沒有改變。
屬性可能是最好的方法。 – Wug 2012-08-06 21:08:35