Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>i would suggest not to use shared methods for all the functions and allow them be called only through instances. Then limit the instantiation (constructor) process. a quick sample: </p> <pre><code>Class DataHost Shared Function GetHost() As DataHost If askPassword() Then Return New DataHost() End If ' Or do something else instead of throw nothing Return Nothing End Function Shared Function askPassword() As Boolean ' ask for password? End Function ''' &lt;summary&gt; ''' Private constructor to avoid external instantiation - thus force external calls to go through factory: GetHost() ''' &lt;/summary&gt; ''' &lt;remarks&gt;&lt;/remarks&gt; Private Sub New() End Sub Sub addName() End Sub Sub delName() End Sub Function getNames() As IEnumerable(Of String) End Function End Class </code></pre> <p>here you can see to call GetNames(), the caller has to have an instance of the DataHost, however, due to the private constructor, the caller has to get an instance of the DataHost through factory method GetHost(). </p> <p>and if you don't want to have many copies of DataHost, you could use singleton as well and return it out in the GetHost() method when password is provided. </p> <p>EDIT: if you really want an event raised out during the process, you could do so at the GetHost method as well: create a private method in the DataHost to raise an event, then after the DataHost is instantiated, call it to throw out the event:</p> <pre><code> Shared Function GetHost() As DataHost If askPassword() Then dim host = New DataHost() host.RaiseSomeEvent() End If ' Or do something else instead of throw nothing Return Nothing End Function </code></pre> <p>then externally the event could be subscribed and handled. </p> <ul> <li>Tweak it according your needs. </li> </ul>
    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. This table or related slice is empty.
    1. This table or related slice is empty.
    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