You can create instances from the name of the class. Note, you can't ask for "MyClass1" without the namespace before it. There are some options for getting from "MyClass1" to "Namespace.MyClass1" such as a Dictionary or even putting the full type name in your database.
Module Module1
Sub Main()
' compiler knows mc1 is a IMyClasses
Dim mc1 = CType(getInstanceFromTypeName("ConsoleApplication1.MyClass1"), IMyClasses)
' compiler doesn't know, mc2 is an object
Dim mc2 = getInstanceFromTypeName("ConsoleApplication1.MyClass2")
mc1.Foo()
mc2.foo()
End Sub
Private Function getInstanceFromTypeName(typeName As String) As Object
Dim o As Object
Try
o = System.Reflection.Assembly.GetExecutingAssembly().CreateInstance(typeName)
Catch ex As Exception
o = Nothing
End Try
Return o
End Function
End Module
Public Class MyClass1
Implements IMyClasses
Public Sub Foo() Implements IMyClasses.Foo
Debug.Print("MyClass1")
End Sub
End Class
Public Class MyClass2
Implements IMyClasses
Public Sub Foo() Implements IMyClasses.Foo
Debug.Print("MyClass2")
End Sub
End Class
Public Interface IMyClasses
Sub Foo()
End Interface
mc1.Foo()
works because mc1 is declared as an IMyClasses, and IMyClasses defines this subroutine. The compiler knows that IMyClasses defines Foo.
mc2.foo()
doesn't work with Option Strict On because Foo() is not a member of Object. With O.S.On, the compiler must be able to resolve all function calls at compile time. It works with Option Strict Off however, as O.S.Off allows function calls on Object, but can potentially be dangerous because O.S.Off also allows mc2.asdf(), for example.
Other resources:
Using System.Reflection
Using System.Activator