View Single Post
Old July 19th, 2007, 10:33 AM
navdeep navdeep is offline
Authorized User
Join Date: Apr 2007
Location: , , .
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts

Thanks a lot Peter for sparing time for me and putting efforts here.

quote:Originally posted by planoie
 I'm not sure how to explain this concept differently than I have. Maybe I can use this analogy:

When I buy a plane ticket I purchase it online. I go to the airport ticket counter and present my ID to the agent who finds my reservation to verify my right to board the plane. She prints me out a ticket. Now I move on to security. They ask for my ticket to verify that I can enter the secure part of the airport. Then I go to the boarding gate. Before I can board the plane I show my ticket again to the gate agent. Then I get on the plane.

In this analogy, I have "login" credentials (my name, maybe a reservation number). The agent verifies that and issues me a printed plane ticket, which I hold. This is like creating a user class instance with the user information in your application. As I move around the different parts of the airport I present my ticket as my authorization to be there. Similarly, as you launch forms of your application, you pass into them (through the constructor) the instance of the user class containing the user's info (ID code, type, etc). The form code uses that information instead of having to check/verify the user's initial credentials.

I got it what you have tried to convey.
It may sound stupid but still user can instantiate the class in a form or a value of static property can be changed accidentally anywhere in the form. How can we prevent that ?

As far as having two classes holding user data goes. I think I get what you mean with that question. If you want to have a full user class (that presumably would closely mirror the data in the database) as well as a smaller version that would be used as the credentials class, that is up to you. I see no reason not to just use the full user class, that would simplify matters. Of course, you could also make a base class that has the basic information you need to carry around the application and extend that for the full user class that maps to the database.

Ya .. using two classes may not be good idea .. this is what my classes look like

Class clsUser
- user_code
- user_name
- user_pass
- user_type

Class clsUserInfo
- user_code (static)
- user_type (static)

I instantiate clsUser during authentication ( login form ). Fetch all properties. Now pass the info to clsUserInfo properties.

clsUserInfo.user_code = myclsUser.user_code
clsUserInfo.user_type = myclsUser.user_type

Now clsUserInfo is available throughout the project. But it does not solve my purpose of accidentally changing values of clsUserInfo properties.