Download THE MELD PROGRAMMING LANGUAGE USER MANUAL
Transcript
MELD PROGRAMMING LANGUAGE
10
FEATURE Bank
INTERFACE:
IMPLEMENTATION:
OBJECT:
CitiSaver : Savings_Account := Savings_Account.CREATE;
CLASS Savings_Account ::=
balance : INTEGER := 0;
METHODS:
"Deposit %d"(cash : INTEGER) --> {
balance := balance + cash;
printf("the balance is %d\n",balance);
}
END CLASS Saving_Account
END FEATURE Bank
Figure 1-6: Bank Program
and, in fact, all orderings of these three action equations are equivalent. Regardless of ordering,
A will be equal to 12 after these three action equations are executed.
1.4. Messages to Objects
Our examples so far have used string messages and string selectors in the methods. The runtime
system, as we saw, sends lines of user input to objects with matching string selectors.
Another form of selector is called the symbolic selector, which matches symbolic messages sent
to an object. The symbolic message and symbolic selector look very similar to a procedure call
and a procedure header in Pascal. Whereas string selectors are used for messages that interact
with the user, symbolic selectors are used for messages internal to the program.
Here is an example of a method using symbolic selectors. Note that selectors look like procedure
headers, and you must have a type for each selector argument: