Localize Module Variable Example

Top  Previous  Next

Suppose we start out with the following meaningless but illustrative code:

 

localizeModuleVariables

 

We have 4 module-level variables, 3 of which are private. There are 2 routines.

a is used in both routines - it must stay module-level
b is only used in the 2nd method. It should be a local variable in that method
c is public (public "fields" like this are not generally considered an OO best practice, but for the sake of this example we'll keep it this way). Since there can be code from outside this module referring to c, we'd better leave it at module level.
d is not used at all. Unless we have future plans for it, we don't really need it.