Please consider the following scenario:
Class Class1
Function Func() as String
End Function
End Class
Class Class2
Function Func() as String
End Function
Function Func2() as String
End Function
End Class
Class Class3
Function GetClassObject as Object
If (certain condition meets)
return new Class1();
Else
return new Class2();
End If
End Function
Main()
Object obj1 = GetClassObject();
obj1.Func(); // Error: obj1.Func() is not defined:
End Main
End Class
Question: How to access obj1.Func() given the condition that for some reason I cannot inherit Class1 and Class2 from a common Interface class?
Thank you
Update: One approach I used to address the problem and failed is as follows:
Interface ICommon
Function Func() as string
End Interface
Class Class3
...
Main()
Dim obj1 as ICommon = TryCast(GetClassObject(), ICommon); //Error: obj1 is "Nothing"
obj1.Func()
or simply:
TryCast(GetClassObject(), ICommon).Func() //Error: obj1 is Nothing
End Main
...
End Class