in reply to Some trouble with closures
If you want to store data that's not shared between different instances (objects) of the same class, an attribute is what you need, and what attributes are there for.
Your description that you don't want the variable shared between various objects indicates that a static variable (emulated by a lexical variable from an outer scope, or implemented by a state variable) is specifically not what you need.
I can recommend a very good book to you: Bertrand Meyer, Object-Oriented Software Construction. If you read that from cover to cover, I can guarantee that you won't confuse attributes with anything else afterwards.
closures cause various side-effects not immediately noticeable that lead to bugs
Every construct leads to bugs when used in a context where it's not appropriate.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Some trouble with closures
by Xiong (Hermit) on Feb 17, 2010 at 15:23 UTC |