B4J Question How Valid is Late Binding with Static Modules

Jorge M A

Well-Known Member
Licensed User
Longtime User
From the point of view of good practices in the B4X Community, how advisable or not, is it to make a dynamic dispatch with static modules (not classes) with the same methods?

Leaving aside the benefits that are lost in the IDE with this modality.

Examples:
B4X:
    Dim thisEngine As Object

    Select pd.EngineType
        Case Engine.ProjectType.MSSQL
            thisEngine = SQLConnect
        Case Engine.ProjectType.MySQL
            thisEngine = MySQLConnect
        Case Engine.ProjectType.ORACLE
            thisEngine = ORAConnect
        Case Engine.ProjectType.MSACCESS
            thisEngine = ACCESSConnect
        Case Else
            thisEngine = Null
            driverClass= ""
            connectionString = ""
    End Select
   
    driverClass         = CallSub(thisEngine, "GetDriverClass")
    connectionString= CallSub2(thisEngine, "GetConnectionString", pd)
    cmdGetCatalogs    = CallSub(thisEngine, "GetCatalogsCmd")
    cmdGetSchema        = CallSub(thisEngine, "GetSchemaCmd")
    cmdGetColumns        = CallSub(thisEngine, "GetColumnsCmd")
   
    thisEngine = Null

B4X:
    Select pd.EngineType
        Case Engine.ProjectType.MSSQL
            driverClass=SQLConnect.GetDriverClass
            connectionString=SQLConnect.GetConnectionString(pd)
            cmdGetCatalogs=SQLConnect.GetCatalogsCmd
            cmdGetSchema=SQLConnect.GetSchemaCmd
            cmdGetColumns=SQLConnect.GetColumnsCmd
        Case Engine.ProjectType.MySQL
            driverClass=MySQLConnect.GetDriverClass
            connectionString=MySQLConnect.GetConnectionString(pd)
            cmdGetCatalogs=MySQLConnect.GetCatalogsCmd
            cmdGetSchema=MySQLConnect.GetSchemaCmd
            cmdGetColumns=MySQLConnect.GetColumnsCmd
        Case Engine.ProjectType.ORACLE
            driverClass=ORAConnect.GetDriverClass
            connectionString=ORAConnect.GetConnectionString(pd)
            cmdGetCatalogs=ORAConnect.GetCatalogsCmd
            cmdGetSchema=ORAConnect.GetSchemaCmd
            cmdGetColumns=ORAConnect.GetColumnsCmd
        Case Engine.ProjectType.MSACCESS
            driverClass=ACCESSConnect.GetDriverClass
            connectionString=ACCESSConnect.GetConnectionString(pd)
            cmdGetSchema=ACCESSConnect.GetSchemaCmd
            cmdGetColumns=ACCESSConnect.GetColumnsCmd
        Case Else
            driverClass=""
            connectionString=""
    End Select

Both ways compile and work well. The first way simplifies maintenance. The second benefits from the advantages of the IDE, such as "Find All References", "Go To Identifier", and the new "Show Sub In windows"!

Are there disadvantages to doing with Late Binding?

Thank you very much for your guidance and observations.
 
Top