挑战在于提出最好的 vb.net 设计模式,该模式将允许在 2 个不同的大型机访问 com 对象之间进行切换。当然这一切都无需改变业务逻辑。
到目前为止,我想出的是一种工厂类型的方法(请参阅下面的精简伪代码)。我有 2 个基于枚举开关实例化的类,它们具有相同的方法和属性,但具有不同的底层对象特定方法。
我是在正确的轨道上还是应该采取另一种方法?谢谢你的帮助。
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Private MFA as MFSession = New MFSession(Enums.mfaccesstype.type1)
Private Sub Form1_Load()
MFA.GotoScreen("XYZ")
End Sub
End Class
Public Class MFSession
Private SystemAccess As Object
End Property
Sub New(ByVal AccessType As Enums.mfaccesstype)
Select Case AccessType
Case Enums.mfaccesstype.type1
SystemAccess = New AccessType1()
Case Enums.mfaccesstype.type2
SystemAccess = New AccessType2()
End Select
End Sub
Public Sub GotoScreen(ByVal ScreenName As String, Optional ByVal Window As String = "")
SystemAccess.GoToScreen(ScreenName)
End Sub
End Class
Public Class AccessType1
Private Type1Object As Object = CreateObject("comobj.Type1Object")
Sub New()
'new session housekeeping
End Sub
Public Sub GotoScreen(ByVal ScreenName As String)
'specialize Type1 method for going to 'ScreenName' here
End Sub
End Class
Public Class AccessType2
Private Type2Object As Object = CreateObject("comobj.Type2Object")
Sub New()
'new session housekeeping
End Sub
Public Sub GotoScreen(ByVal ScreenName As String)
'specialized Type2 method for going to 'ScreenName' here
End Sub
End Class