Hello:
I am thinking of an object called "user." This object will be instatntiated
during a login process. But I want to use this to control the behavior of the
application since it will also encapsulate the logged-in user's security
profile.
What is the best strategy for creating one such object?
I initially thought of having a module wherein it is declared public. Even
if I do, I may need to pass in as a parameter by reference to the Login form
and by value to other forms. Would I have to have parameters in the forms'
New subroutine? Or, is there a more elegant way to make this exposed
throughout the application?
Venkat
Tom Shelton - 26 Oct 2004 05:21 GMT
> Hello:
>
[quoted text clipped - 12 lines]
>
> Venkat
You could always create the object as a singleton...
Public Class User
Private Shared instance As User
' Allow no uncontroled instances
Private Sub New ()
End Sub
' Create a shared constructor - this
' will be called sometime before first access
Shared Sub New ()
instance = new User ()
End Sub
' do all your properties/methods
Public Shared Function GetInstance () As User
Return User.instance
End Sub
End Class
This is a very simple example - but essentially what this allows is that
anywhere in your code you can say:
Dim currentUser As User = User.GetInstance ()
' Do stuff
And all parts of your program will refere to the single shared instance
of the User class.

Signature
Tom Shelton [MVP]
vvenk - 26 Oct 2004 11:29 GMT
Tom:
Wonderful suggestion. Thanks.
> > Hello:
> >
[quoted text clipped - 43 lines]
> And all parts of your program will refere to the single shared instance
> of the User class.