O'Reilly logo
  • Ervin Varga thinks this is interesting:

Advantages of Access Routines


Cover of Code Complete, Second Edition


There is one additional advantage of using access routines for global data not mentioned in the book. Namely, to control the level of global variables, i.e. what really the term "global" means. A variable may be global for the whole application at the beginning, when it is still single-threaded. However, later on during maintenance, maybe the application is going to be multi-threaded, and some application global vars would become thread global instead (each thread would have its own "global" variant).Leveraging access routines it is easy to change the semantics of such global variables. For example, in Java you would store the value of a variable inside the ThreadLocal instance, though. At any rate, access routines...