Avoiding global variables in event-driven programming

This is a style/design question.

I've always been told to avoid global variables, which was easy when there were no user events to interrupt flow of control(to execute a method, just 'send' it what it needs, no mess). However, in executing code that is triggered by an event, I find that the needed info has to be 'taken'. The only way I've seen to do this is to start making, what were local variables, global, so that event triggered code has access. But, as my classes get bigger, I'm running into the coupling problem of not being sure of where these variables are being changed.

Am I making any sense?

Any suggestions?

[662 byte] By [NexonL] at [2007-9-27 14:30:18]
# 1

So... don't allow them to be changed. Declare them private, and require them to be changed via a setter method. I realize that doesn't answer your question about how you can know what's changing the variable, because it replaces it with a question about what's calling the method. However, if the variable is part of a properly-designed object, you shouldn't need to worry about what else is using it when.

DrClap at 2007-7-5 22:29:36 > top of Java-index,Archived Forums,Java Programming...
# 2
public variables (non static final and in ALL_CAPS) are Evil and a major source of clumsy code. You should only create private variables and create setter and getter methods for them (when appropriate).dave
seconddevil at 2007-7-5 22:29:36 > top of Java-index,Archived Forums,Java Programming...