PC Review


Reply
Thread Tools Rate Thread

Creating an object that has the entire application scope.

 
 
=?Utf-8?B?dnZlbms=?=
Guest
Posts: n/a
 
      26th Oct 2004
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

 
Reply With Quote
 
 
 
 
Tom Shelton
Guest
Posts: n/a
 
      26th Oct 2004
On 2004-10-26, vvenk <(E-Mail Removed)> wrote:
> 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
>


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.

--
Tom Shelton [MVP]
 
Reply With Quote
 
=?Utf-8?B?dnZlbms=?=
Guest
Posts: n/a
 
      26th Oct 2004
Tom:

Wonderful suggestion. Thanks.

"Tom Shelton" wrote:

> On 2004-10-26, vvenk <(E-Mail Removed)> wrote:
> > 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
> >

>
> 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.
>
> --
> Tom Shelton [MVP]
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating an Outlook application object on Vista (UAC) Yuri Nijsen Microsoft Outlook VBA Programming 0 14th Jul 2008 12:55 PM
Creating an Outlook application object on Vista (UAC) Yuri Nijsen Microsoft Outlook Discussion 3 14th Jul 2008 12:45 PM
creating Excel Application Object in C#? =?Utf-8?B?U2l4U2lnbWFHdXk=?= Microsoft Excel Programming 2 10th Jul 2006 09:55 PM
how did a singleton object achieve application scope in asp.net when it was declared a page variable? Rich Microsoft ASP .NET 5 22nd Feb 2006 11:38 PM
How to persist an object in an entire life an asp.net application J-T Microsoft ASP .NET 3 19th May 2005 02:22 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:29 AM.