Variables
Damien Cassou, Stéphane Ducasse and Luc Fabresse
http://stephane.ducasse.free.fr
In a Nutshell
- Local variables start with lowercase (temps, instance variables, arguments,...)
- Shared variables start with uppercase (class, class variables)
Local Variables Start With Lowercase
Temporary variables are local to the method
Example: c
Remember: class names start with uppercase
Local Variables Start With Lowercase
Instance variables are local to the object
Example: x
, y
, count
Local Variables Start With Lowercase
Method arguments: aPoint
Block arguments: :x
Special Variables
Special variables cannot be changed
true
, false
, nil
self
, super
, thisContext
Special Variables
true
, false
are the Booleans
true
is the unique instance of the class True
false
is the unique instance of the class False
nil
is the unique instance of the class UndefinedObject
Special Variables
self
refers to the receiver of the message (this
in Java)
super
refers to the receiver but the method lookup starts in the superclass of the class defining the method (see dedicated Lectures)
thisContext
refers to the current execution stack (advanced)
Shared or Global Variable starts with Uppercase
Object
is a class globally accessible
Transcript
is an object that is globally accessible (a kind of stdout)
ClassVariables are Shared Variables
- To share information between all the instances of a class and subclasses
- Use a classVariable
- Here
Compositions
is shared between all the CombinedChar
instances and instances of subclasses
Summary
- Lowercase are used for local/private/temporary variables
- Uppercase are used for shared or global variables
/