473,322 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Creating an object that has the entire application scope.

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

Nov 21 '05 #1
2 1216
On 2004-10-26, vvenk <vv***@discussions.microsoft.com> 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]
Nov 21 '05 #2
Tom:

Wonderful suggestion. Thanks.

"Tom Shelton" wrote:
On 2004-10-26, vvenk <vv***@discussions.microsoft.com> 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]

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()',...
1
by: ajit goel | last post by:
Hi; I have a question which respect to initialising and creating objects in loops.Here are the 2 scenarios: 1. ###############################################################################...
16
by: Mcginkel | last post by:
I am trying to find a way to load XHTML content in an Iframe. I use to do this in html by using the following code : var iframeObject = document.createElement("iframe");...
21
by: Sharon | last post by:
I wish to build a framework for our developers that will include a singleton pattern. But it can not be a base class because it has a private constructor and therefore can be inherit. I thought...
5
by: Rich | last post by:
The following code produced a singleton object with application scope when it should have had page scope: public class Singleton { private static Singleton uniqueInstance = null; private...
26
by: yb | last post by:
Hi, Is there a standard for the global 'window' object in browsers? For example, it supports methods such as setInterval and clearInterval, and several others. I know that w3c standardized...
17
Motoma
by: Motoma | last post by:
This article is cross posted from my personal blog. You can find the original article, in all its splendor, at http://motomastyle.com/creating-a-mysql-data-abstraction-layer-in-php/. Introduction:...
9
by: Tony Proctor | last post by:
I need to create a process Singleton object for an ASP application, but I'm having some odd issues In my GLOBAL.ASA, I have an <OBJECTelement specifying the relevant ProgID with RUNAT=Server and...
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.