发信人: kamkam(KK)
整理人: kamkam(2002-05-04 21:58:47), 站内信件
|
这里开始的内容属于domino 对象模型。
利用后期初始化和对象重用技术来最大限度地利用资源
1.后期初始化(lazy initialization)。学习到一定地步的lotus程序员,为了程序结果清晰,往往喜欢事先将一些对象如db , view , doc等初始化,然后每个函数都可以使用。从提高效率的角度,可以改进为使用后期初始化(自己翻译的,不知道是否准确,应用期初始化?),下面是后期初始化的方法
' *** Globals
' *** Declare the global data we share
Public gDb As NotesDatabase
Public gVwCustomerType As NotesView
'*** Functions
'*** Get the customer type view (lazy initialization)
'*** Do account validation
Sub Initialize
'*** Set up the database (NOT lazy)
Dim ss As New NotesSession
Set gDb = ss.CurrentDatabase
End Sub
Function GetCustomerTypeView() As NotesView
'*** Only get it the 1st time it is used
If (gVwCustomerType Is Nothing) Then
Set gVwCustomerType = gDb.GetView("Customer Type")
End If
Set GetCustomerTypeView = gVwCustomerType
End Function
Function ValidateAccount(custName As String, _
accountType As String) As Integer
'*** Return True if account is valid
Dim vw As NotesView
Dim doc As NotesDocument
Dim aKeys(0 To 1) As String
Select Case AccountType
Case “New”
'*** New accounts are always valid
ValidateAccount% = True
Case Else
'*** Is customer allowed the specified account type?
Set vw = GetCustomerTypeView()
aKeys(0) = custName$
aKeys(1) = accountType$
Set doc = vw.GetDocumentByKey(aKeys, True)
If (doc Is Nothing) Then
ValidateAccount% = False
Else
ValidateAccount% = True
End If
End Select
End Function
以上GetCustomerTypeView函数中使用了lazy initialization方法,当该函数第一次被调用,它调用getview取得视图,以后只要直接取public的vw即可,其他程序的结构不会受到影响(如果将全局变量的vw封装在class中,则更加符合面向对象的规则)
---- ---------------
我心是澎湃的海 我心是动荡的舟 |
|