Budd uses technique of delegating responsibility to an aggregate
object (in this case a neighboring queen).
Each queen considers he position only with regard to her neighbor
on one side. This leads naturally to a linear structure.
How does Budd terminate the linear structure? What can you do
in languages that support pointers? What can you do in languages
without pointers?
The technique involved in Budd's program using generating
and filtering.
Queens are numbered by the column in which they reside.
first-position attempts to generate an initial
solution for a queen and all her lower numbered neighbors.
test-or-advance checks the current position for
feasibility and either returns true to indicate it
satisfies the test or returns the result of generating
the next feasible solution.
check-row checks a row and column position against
a particular queen to see if the queen or any of her lower
numbered neighbors can attack that position.
next-position attempts to generate the next
feasible solution for a queen and all her lower numbered
neighbors.
Dylan Eight-Queens Example
module: dylan
author: Joseph N. Wilson
copyright: 1996 Joseph N. Wilson
description: Dylan example of the eight queens program strategy
employed by Budd in Chapter 5 of his book *An Introduction to
Object-Oriented Programming*.
define class (
Programming Assignment Due Wednesday 28 February
Modify the Dylan program to solve exercises 1 and 2 of page 84. Don't
worry about filtering rotations.
Static and Dynamic Binding
Bindings of interest: variable to type and message to
method
Type may be associated with a variable or a value or both.
An expression is type correct if it can be evaluated without
any errors arising from objects belonging to classes
without the methods required to carry out evaluation of the
expression.
Languages in which it is possible to guarantee that all expressions
are type correct before running the program are saod to be
strongly typed.
If an OOP uses classes as types, then assignment of subclass objects
to superclass variables introduces a new twist in this old problem.
The type of a variable (its static class) may not match
the type of the value it denotes (its dynamic class).
Consider the following Dylan fragment:
define variable n :: = 1;
object-class (n);
n := 3.3;
object-class (n);
n := "abcde";
Explain the behavior of the interpreter in evaluating this sequence
of constituents.
The Container Problem
Budd's example: class Ball with derived classes
BlackBall and WhiteBall.
Make a ball container. Insert a ball. Is it a black ball
or is it a white ball.
Without run time type information (RTTI) it is impossible
to distinguish what kind of ball is contained within the container.
How would one define such a container in C++?
You've already seen a case of a container, namely, a button.