B4J Question How Valid is Late Binding with Static Modules

Discussion in 'B4J Questions' started by Jorge M A, Dec 3, 2019 at 11:18 PM.

  1. Jorge M A

    Jorge M A Active Member Licensed 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:
    Code:
    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

    Code:
    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.
     
    Sandman likes this.
  2. Erel

    Erel Administrator Staff Member Licensed User

    If thisEngine is a local variable then you don't need to "null" it.

    Both options are good. Use the one that is easier for you to build and maintain.
     
    Jorge M A likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice