Temporary variables are local to the method
Example: c
CounterTest >> testIncrement
| c |
c := Counter new.
...
Remember: class names start with uppercase
Instance variables are local to the object
Example: x
, y
, count
Object subclass: #Point
instanceVarNames: 'x y'
Object subclass: #Counter
instanceVarNames: 'count'
Method arguments: aPoint
crossProduct: aPoint
"Answer a number that is the cross product of the receiver and the
argument, aPoint."
^ (x * aPoint y) - (y * aPoint x)
Block arguments: :x
[ :x | x + 2 ]
Special variables cannot be changed
true
, false
, nil
self
, super
, thisContext
true
, false
are the Booleanstrue
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
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)
Object
is a class globally accessible
Object subclass: #Point
Transcript
is an object that is globally accessible (a kind of stdout)
Transcript cr.
Transcript show: 'hello world'.
Transcript cr.
Object subclass: #CombinedChar
instanceVariableNames: 'codes combined'
classVariableNames: 'Compositions Decompositions Diacriticals'
package: 'Kernel-BasicObjects'
Compositions
is shared between all the CombinedChar
instances and instances of subclasses/