There is no difference between using App for a database property or a module, it is a decision of taste. But both introduce global state into the application. The property is accessible from everywhere and therefore will be accessed from everywhere.
Stop reading here if you do not care about global state (in a lot off smaller applications it does not really matter).
This is a possible approach for avoiding global state:
Subclass the specific SQLiteDatabase, MySQLCommunityServer, etc. class and add everything related to it in that subclass.
Create a private computed property Database As MySQLiteDatabase in App. The setter stays empty. The getter has this code:
// creates one instance only, the first time the property is accessed
Static db As MySQLiteDatabase
If db Is Nil Then
db = New MySQLiteDatabase()
End
Return db
As the App’s Database property is set to private, it can not be accessed by the rest of the application directly, instead one needs to hand it over to each class using it. So every class, every window, etc. has a constructor, which contains (besides others) a parameter db As MySQLiteDatabase.
The advantages:
Makes testing classes easier, since all dependencies (not only the database) must be handed over in the constructor. It is nearly impossible to test a class which depends on public properties in App or modules and where your code within the class has lines like If App.Database.Connect() … or MyModule.DoSomething().
Makes using classes in a different project much simpler. You just copy and paste the class. You will not be able to compile until all constructor demands are satisfied. Once they are satisfied you compile and the application works. With global state you would need to change all lines of your class to access the global variables before being able to compile. Not using global variables also means one does not have to check if all the global variables are initialized to non-Nil when you need to use them in a class. Just check once for non-Nil for each argument in the constructor.
The “mental image” of the application in term of the dependencies within a project changes from a complex graph to a series of function calls. Like App > choose Sqlite file > login as user > select company > open contacts window > … Instead of App > choose Sqlite file (uses DBModule) > login as user (uses DBModule and UserModule) > select company (uses DBModule and UserModule and CompanyModule) >…
Each class, window, etc. has one entry point, the constructor, and one exit point returning one or several values (I always call it Close()).