View Single Post
  #14 (permalink)  
Old July 19th, 2007, 02:32 PM
planoie's Avatar
planoie planoie is offline
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

As I outline above, if you only set those values in the user class constructor then no one can change them in the properties. Of course, you could create a new instance of a user class, but there isn't much you can do to prevent that.

If you use a class with static properties there is *no* way you can prevent other code from setting the values, because the static getter/setter is the only way to set them. Well, that's not entirely true, you could write a static method on that same class that assigns the value to the static internal variable. But that isn't preventing assignment, just obfuscating it a bit.

I'm not sure that you are understanding my explanations, and I have run out of ways to explain it. You don't need to use static properties on a class if you hand the instance of the class around between the forms. This will prevent other code from assigning values to the properties.

-Peter
Reply With Quote