Class and Method Definitions
Damien Cassou, Stéphane Ducasse and Luc Fabresse
http://stephane.ducasse.free.fr
Class and Method Definitions in Pharo
- classes and methods are defined within tools
- there is no dedicated syntax
Class Definition in Pharo
Class Definition is a Message
We send the message subclass:inst....
to the superclass to create the class
Method Definition in Pharo
Method Definition in Pharo
In which class is factorial
defined?
Presentation Convention
In this lecture, a method will be displayed as
- Integer >> is not part of the syntax
- it tells you the method's class
Presentation Convention
In Pharo, the method belongs to the selected class
Remember Messages
factorial
is the method name
=
, >
, *
and -
are binary messages
factorial
is an unary message
ifTrue:
and error:
are keyword messages
- the caret
^
is for returning a value
A Method Returns self by Default
is equivalent to
Class Methods
- press the button
class
to define a class method
- in lectures, we add
class
What You Should Know
- A class is defined by sending a message to its superclass
- Classes are defined inside packages
- Methods are public
- By default a method returns the receiver,
self
- Class methods are just methods of the class side
/