Class Methods
Damien Cassou, Stéphane Ducasse and Luc Fabresse
http://stephane.ducasse.free.fr
Class Methods
- in Pharo, everything is an object
- objects can receive messages
- classes are objects too
Classes can receive messages
Examples
The message now
is sent to the class Time
The message today
is sent to the class Date
Examples
Class Methods are Defined on Class Side
Note the Class
button pressed!
Common Mistake
Counter withValue: 10
returns the class Counter
instead of a new instance
Why?
is equivalent to
self
here is the class Counter
(the receiver of the message)
Solution
Summary
- Classes are objects
- Messages can be sent to classes too
- Class-side methods are no different from other methods
- Most class-side methods create new instances
- To define a class-side method, press the
class
button
/