Perfect Developer basic tutorial 5 | This page last modified 2011-10-31 (JAC) |
1. When you need to add a new method to a class, on what basis should you decide whether to declare it as a function or as a schema?
If the method needs to modify something, it must be declared as a schema, since functions
cannot modify anything.
If the method merely needs to compute and return one or more values, it should be declared
as a function.
2. You are given the following partial class declaration:
class ListOfIntegers ^=
Write a method to return the number of items in the list and a method to add a new item to the end of the list.
abstract
var list: seq of int;
interface
build{}
post list! = seq of int{};
end;
Insert the following in the interface section:
function itemCount: nat
^= #list;
schema !addItem(item: int)
post list! = list.append(item);