As above by @EnriqueGonzalez
In addition:
If they are globals , you have to prefix their use each time by the global class/model name - an extra inconvenience.
In terms of memory and speed, there is no discernable difference after compilation.
They don't get their own instance even if you declare them in individual modules as they are to all intents and purposes static classes as far as B4x is concerned, think code modules. Otherwise the XUI.DefaultFolder couldn't work as it does. Declare them where you need them.
They don't get their own instance even if you declare then in individual modules as they are to all intents and purposes static classes as far as B4x is concerned, think code modules. Otherwise the XUI.DefaultFolder couldn't work as it does. Declare them where you need them.
Sub Process_Globals
Private MainForm As Form
Private Button1 As B4XView
Private fx As JFX
Private xui As XUI
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("Layout1")
MainForm.Show
End Sub
Sub Button1_Click
xui.SetDataFolder("MadeUpFolder")
Log(MyModule.xui.DefaultFolder)
For i=0 To 5
Dim mc As MyClass
mc.Initialize
Log(mc.MyXUI.DefaultFolder)
Next
End Sub
MyModule:
'Static code module
Sub Process_Globals
Public xui As XUI
End Sub
MyClass:
Sub Class_Globals
Private xui As XUI
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
End Sub
Public Sub getMyXUI As XUI
Return xui
End Sub
Logs:
WARNING: package com.sun.javafx.embed.swing.oldimpl not in javafx.swing
Waiting for debugger to connect...
Program started.
C:\Users\Chris\AppData\Roaming\MadeUpFolder
C:\Users\Chris\AppData\Roaming\MadeUpFolder
C:\Users\Chris\AppData\Roaming\MadeUpFolder
C:\Users\Chris\AppData\Roaming\MadeUpFolder
C:\Users\Chris\AppData\Roaming\MadeUpFolder
C:\Users\Chris\AppData\Roaming\MadeUpFolder
C:\Users\Chris\AppData\Roaming\MadeUpFolder