' The object creation
Sub CreateObject (option As Int)
Dim X As Object
If option = 1 Then
Dim M1 As Class1
M1.initialize
X=M1
Else if option = 2 Then
Dim M2 As Class2
M2.initialize
X=M2
Else
Return
End If
UseTheObject(X)
End Sub
' The dispatcher
Sub UseTheObject (X As Object)
' Calling some class methods...
If SubExists(X,"Foo1") Then CallSub(X,"Foo1")
If SubExists(X,"Foo2") Then CallSub2(X,"Foo2","xyz")
If SubExists(X,"Foo3") Then CallSub3(X,"Foo3","abc","123")
' Calling with multiple parameters
Dim Args As Map=CreateMap("Param1":1,"Param2","xyz","Param3","abc123")
If SubExists(X,"FooM") Then CallSub2(X,"FooM",Args)
Dim FooRes As String=Args.GetDefault("RetParam","")
End Sub