Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>One thing you could do is create a factory for the <code>DatabaseManager</code> and then just have all your other code call it from that factory. I'm very out of practice with VB syntax, but in C# it might look something like this:</p> <pre><code>public class DatabaseManagerFactory { private static DatabaseManager _current = null; public static DatabaseManager Current { get { if (_current == null) _current = new DatabaseManager(); return _current; } } } </code></pre> <p>VB</p> <pre><code>Public Class DatabaseManagerFactory Private Shared _current As DatabaseManager = Nothing Public Shared ReadOnly Property Current As DatabaseManager Get If _current Is Nothing null Then _current = New DatabaseManager() Return _current End Get End Property End Class </code></pre> <p>The idea then is that anything in your application which needs to use a <code>DatabaseManager</code> would just call <code>DatabaseManagerFactory.Current</code> to get the one shared instance.</p> <p>Note that in this case <code>DatabaseManager</code> isn't really a singleton, you can still instantiate one elsewhere in the application if you need to for some reason. If it should be an actual singleton then you'd want to make some modifications to the <code>DatabaseManager</code> class itself. Maybe give it a private constructor and implement this factory directly on the class? Something like this:</p> <pre><code>public class DatabaseManager { private static DatabaseManager _current = null; public static DatabaseManager Current { get { if (_current == null) _current = new DatabaseManager(); return _current; } } private DatabaseManager { // your initialization of the class } } </code></pre> <p>VB</p> <pre><code>Public Class DatabaseManager Private Shared _current DatabaseManager = Nothing Public Shared ReadOnly Property Current As DatabaseManager Get If _current Is Nothing Then _current = New DatabaseManager() Return _current End Get End Property Private Sub New() ' your initialization of the class End Sub End Class </code></pre> <p>(I encourage anybody more familiar with VB syntax to edit this answer accordingly to better address the question.)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload