object-oriented computation --- class-based programming
The first design goal is to lay-out the various classes of data that a program processes and how these forms of data interrelate.
Sounds familiar? This is all the work we go through before we get to do the "real" stuff: programming.
So what form of data does Java offer? We know from the first few weeks that we want:
numbers (5, 7.45; no fractions, no complex): 5 + 55
int, double
Booleans (true, false): if true ...
boolean
Integer objects new Integer(5): new Integer(5).plus(55)
Integer
Boolean objects new Boolean(true)
Integer
In the Scheme world:
(define-struct monkey (legs space)) ;; A monkey is a structure: (make-monkey number number). ;; Creating a monkey: (make-monkey 4 55)
In Java:
class Monkey {
int legs;
int space:
Monkey(int _legs, int _space) {
legs = _legs;
space = _space;
}
}
// Creating a Monkey:
new Monkey(4,55)
In the Scheme world:
(define-struct spider (legs space)) ;; A spider is a structure: (make-spider 8 .2) (define-struct elephant (legs space)) ;; An elephant is a structure: (make-elephant 8 200) ;; An animal is either ;; - a monkey ;; - an elephant ;; - a spider.
In the Java world:
interface Animal {}
class Spider implements Animal {
int legs;
int space;
Spider(int _legs, int _space) {
legs = _legs;
space = _space;
}
}
class Elephant implements Animal {
int legs;
int space;
Elephant(int _legs, int _space) {
legs = _legs;
space = _space;
}
}
class Monkey implements Animal {
int legs;
int space;
Monkey(int _legs, int _space) {
legs = _legs;
space = _space;
}
}
In the Scheme world:
(define-struct child (name father mother)) ;; An family tree is either ;; - empty ;; - or a structure: (make-child symbol FT1 FT2) ;; where FT1 and FT2 are family trees.
In the Java world:
interface FamilyTree {}
class Empty implements FamilyTree {}
class Child implements FamilyTree {
String name;
FamilyTree father;
FamilyTree mother;
Child(String name, FamilyTree _father, FamilyTree _mother) {
name = _name;
father = _father;
mother = _mother;
}
}
// Creating Family Trees:
new Empty()
new FamilyTree("Ben", new Empty(), new Empty())
| Matthias Felleisen | This page was generated on Fri Feb 26 14:50:00 CST 1999. |