Article Preview
Buy Now
COLUMN
Implementing the Monostate Pattern
Static Variables In Action
Issue: 4.1 (September/October 2005)
Author: Charles Yeomans
Author Bio: Charles is the author of "I Declare: Calling External Functions in REALbasic", available online at
Article Description: No description available.
Article Length (in bytes): 5,947
Starting Page Number: 33
Article Number: 4115
Related Web Link(s):
http://www.quantum-meruit.com/rb/
Excerpt of article text...
REALbasic 2005 adds the concept of a static variable to the language. To get a grasp of this new addition, consider the concept of a local variable. A local variable is a chunk of storage allocated in a method. This variable is created anew every time the method executes, thus each executing copy of the method has its own local storage.
A static variable is also a chunk of storage allocated in a method. Unlike a local variable, a static variable is created and initialized once, remains in existence until the application quits, and is shared by all executing copies of the method. Like a local variable, the visibility of a static variable is limited to the method in which it is declared.
It is important to understand that static variables belong to the method, not the object or module to which the method is attached. Thus the creation and destruction of objects do not affect the value of static variables.
Static Properties
Static variables should not be confused with class properties, though they will be. Although REALbasic does not offer class properties, it is possible to implement the functionality of class properties using static variables, if not the syntax.
The initial temptation is to write a get/set pair of methods to express a class property, just as one can do for object properties. However, since static variables cannot be visible to two methods, this approach won't work. So we resort to indirection.
...End of Excerpt. Please purchase the magazine to read the full article.