- Local time
- Yesterday, 21:56
- Joined
- Feb 28, 2001
- Messages
- 28,621
I'll start by saying that it is my OPINION, clearly indicated as such, that this particular use of TempVars seems like a bad approach to me. When you write non-class code that deals with global values that persist across multiple iterations, there is a potential for a situation in which your variables can be changed outside of the code for which those variables exist. We call that a side-effect and it is generally not considered to be a good idea.
A class object is supposed to be like a black box. When you create a class, the whole point of a property Let or property Get or property Set routine is that you want to set class variables that are protected (or if you prefer, isolated) within the body of the class object. When using a TempVar as the place where you keep your object properties, you can easily bypass those protections, in effect cheating your way around the sides of the black box. With careful attention to the issue, you can of course avoid causing a problem, but I think that here, we have in essence a dangerous short-cut that invites side-effect meddling.
If you say "Oh, this makes it easier to define the object" ... I don't disagree. It may, indeed, be EASIER to populate arbitrary properties when you use a TempVars method for storing object properties. However, remember that a TempVars variable can only be string or numeric. If the class object can contain an object then the TempVars container cannot contain it. Granted, the amount of work needed to set up that class object's internal data might be tedious - but that is a price you pay for the "black box" effect that is part of class objects.
Then there is the issue of whether you would wish to implement two instances of the object. In a traditional class object, no problem. You just create a new instance of the object which contains everything you need. But a TempVars isn't stored with the class object so now you would have to either avoid two objects or have more complex code to use alternate names for the 2nd (or later) TempVars "container."
Again, an OPINION as to why TempVars for class object properties might represent a problem. And I understand that some folks might disagree with a "hard line" stand here.
A class object is supposed to be like a black box. When you create a class, the whole point of a property Let or property Get or property Set routine is that you want to set class variables that are protected (or if you prefer, isolated) within the body of the class object. When using a TempVar as the place where you keep your object properties, you can easily bypass those protections, in effect cheating your way around the sides of the black box. With careful attention to the issue, you can of course avoid causing a problem, but I think that here, we have in essence a dangerous short-cut that invites side-effect meddling.
If you say "Oh, this makes it easier to define the object" ... I don't disagree. It may, indeed, be EASIER to populate arbitrary properties when you use a TempVars method for storing object properties. However, remember that a TempVars variable can only be string or numeric. If the class object can contain an object then the TempVars container cannot contain it. Granted, the amount of work needed to set up that class object's internal data might be tedious - but that is a price you pay for the "black box" effect that is part of class objects.
Then there is the issue of whether you would wish to implement two instances of the object. In a traditional class object, no problem. You just create a new instance of the object which contains everything you need. But a TempVars isn't stored with the class object so now you would have to either avoid two objects or have more complex code to use alternate names for the 2nd (or later) TempVars "container."
Again, an OPINION as to why TempVars for class object properties might represent a problem. And I understand that some folks might disagree with a "hard line" stand here.