Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
balance balance
Each object is an instance of some class. The class
defines the internal structure and the behavior of all its deposit: balance ~- balance + amount
instances. The object shown above might be an instance of
class BankAccount. IF balance < amount THEN false
withdraw: ELSE
Processing is invoked by sending messages to objects. balance ~- balance - amount
Sending a message to an object is very much like calling a
procedure in a procedural language. Among the messages to When a message is sent to an object, the selector is
which a bank account could respond might be: looked up in the message dictionary of the object's class in
balance order to find the appropriate method to execute. Thus, there
is an important difference between sending a message in
deposit:" amount Smalltalk and calfing a procedure in a procedural language.
The decision of exactly which response is appropriate is left to
withdraw: amount
the receiver instead of being decided ahead of time by the
A message consists of an identifying key called a selector and sender. The exclusive use of such "generic" procedures
enhances modularization of programs, because the sender of a
zero or more arguments. The selectors of the messages shown
message doesn't have to be concerned at all about the internal
above are balance, deposit.:, and withdraw:. Two of those
messages have an argument named amount. structure, or even the class, of the receiver.