A phenomenon that is more usually regarded as being a problem in structured programming languages than in object-oriented languages. In a structured programming language, such as Pascal or C, a global variable is one defined outside the procedures and functions of a program. It is difficult to keep track of the usage of such a variable as it is readable and writable by the whole program or module in which it is defined. This makes such variables a common source of logical errors. In fact, instance variables pose a similar problem within class definitions, since Java's scope rules make them accessible to all methods defined within a class. This is one of the reasons why we prefer to channel access to instance variables through accessor and mutator methods even within a class.
- Browse Related Terms: global variable, high level programming language, identifier, native method, object-oriented language, stepwise refinement, structured programming, transient