Introduction to the design recipe for class-based data definitions: class definition, class diagram, the constructor, examples of the instances of data.
simple classes
classes with containment
unions of classes
/*
+-------+
| Posn |
+-------+
| int x |
| int y |
+-------+
*/
// to represent one point on a canvas
class Posn {
int x;
int y;
Posn(int x, int y) {
this.x = x;
this.y = y;
}
}
/* Interactions:
Examples of constructing instances of Posn
Posn p1 = new Posn(10, 20);
Posn p2 = new Posn(20, 20);
Examples of the use of the field selectors for the class Posn
p1.x -- expected: 10
p1.y -- expected: 20
p2.x -- expected: 20
p2.y -- expected: 20
*/