November 15, 1999
Reminder: Plagiarism will not be tolerated. One team copied many sentences from web pages without any acknowledgement. That team is getting zero for this project.
Several teams copied sentences from sources that they cited. If you do this, you must:
Object identity is connected to an "object-centric" view of programming: every operation is about some primary object. Syntactically, every method has an unwritten (implicit) first argument, which is the object itself.
(2) Encapsulation. The state of an object is private to the object: the only way the state can be changed or observed is by calling one of the object's methods. This is what we called "implementation-hiding" before.
(3) Overloading. Two objects of different classes can have a
method with the same name. If these methods perform conceptually similar
operations, the caller of the method does not need to know the exact class
of the called object. Overloading is particularly important with
inheritance.
According to this view, the object itself is really a dispatcher: it waits for a message and then selects one of its methods for execution based on which message was received. A class is a function that can generate new objects. For example:
Here newgenerator is a higher-order function that returns another function, which is anonymous. Each returned function is a pseudo-random number generator (PRNG) that can respond to two alternative messages.type messages = (next, restart);function newgenerator (initial:real) =
begin
var seed: real := initial;
return
function (m: messages) =
begin
case m of
next: seed := transform(seed);
restart: seed := initial;
end;
return seed;
end;
end;function myrandom = newgenerator(1.2345);
function hisrandom = newgenerator(0.1428);
The updated PRNG seed is kept in the variable seed which is
local to newgenerator so seed is fresh each time that
newgenerator
is called. However seed is global to the anonymous function
so each version of seed keeps its value between calls to the corresponding
individual PRNG.
(0) The single entry, single exit property should be preserved: that control can only flow into the command at one point, and can only flow out at one point.
(1) It should be possible to raise exceptions and recover from them for any command, not just loops. There can be reasons to abort any command.
(2) When an exception is handled, it should be possible to execute some recovery commands as an alternative to the regular command which gave rise to the failure. For example if an exception is raised while reading an input value, it should be possible to recover by assigning a default value.
(3) It should be possible to provide exception handlers for many different types of exception.
(4) Providing exception handlers should be optional. If a handler is not provided, the exception should cause an escape from the enclosing block.
(5) Programmer-defined exceptions like "negative age" should be allowed in addition to system-defined exceptions like "division by zero".