[Instructions] [Search] [Current] [Syllabus] [Links] [Handouts] [Outlines] [Labs] [More Labs] [Assignments] [Quizzes] [Examples] [Book] [Tutorial] [API]
Back to More Binary Representation. On to Design, Revisited.
Held Wednesday, April 7
Summary
Contents
Notes
ints, we need
40 bytes. (Each int is 4 bytes.)
Person class:
public class Person {
int id;
String name;
public Person(String name) { ... }
public Person(String name, int id) { ... }
public int getId() { ... }
public void setId(int newid) { ... }
...
} // class Person
Persons as
Person0:
+-------+
Methods:| *--------------------------+
+-------+ +---+ |
name:| *----------->| S | |
+-------+ +---+ |
id:| 32 | | a | |
+-------+ +---+ |
| m | |
Person1: +---+ v
+-------+ +-------+
Methods:| *--------------------->| | equals(Object)
+-------+ +-------+
name:| *-------+ | | toString()
+-------+ | +-------+
id:| 99 | | | |
+-------+ | ...
| | |
v +-------+
+---+ +----------* | getId()
| C | | +-------+
+---+ | | | setId(int)
| l | | +-------+
+---+ | | |
| i | | ...
+---+ | | |
| f | | +-------+
+---+ | | | Person(String)
v +-------+
Code for getId +------* | Person(String,int)
return the | +-------+
value at |
offset 8 |
v
Code for Person(String,int)
|
SalariedPerson
public class SalariedPerson
extends Person
{
float salary;
public SalariedPerson(String name, float salary) { ... }
public void giveRaise(float amt) { ... }
} // class SalariedPerson
employee:
+-------+ +-------+
Methods:| *--------------------->| | equals(Object)
+-------+ +-------+
name:| *-------+ | | toString()
+-------+ | +-------+
id:| 99 | | | |
+-------+ | ...
salary: | 11.99 | | | |
+-------+ v +-------+
+---+ +-----------* | getId()
| X | | +-------+
+---+ | | | setId(int)
| e | | +-------+
+---+ | | |
| n | | ...
+---+ | | |
| a | | +-------+
+---+ | | | super(String)
| +-------+
| +------* | super(String,int)
v | +-------+
Code for getId | | | giveRaise(float)
return the | +-------+
value at | | | SalariedPerson(String,float)
offset 8 | +-------+
| | |
| ...
v
Code for Person(String,int)
|
Person are in
the same order. That way, a method that expects a person can still take
a SalariedPerson and behave in exactly the same
way. (getId is one such method.)
History
Back to More Binary Representation. On to Design, Revisited.
[Instructions] [Search] [Current] [Syllabus] [Links] [Handouts] [Outlines] [Labs] [More Labs] [Assignments] [Quizzes] [Examples] [Book] [Tutorial] [API]
Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.
This page may be found at http://www.math.grin.edu/~rebelsky/Courses/CS152/99S/Outlines/outline.35.html
Source text last modified Wed Apr 7 10:44:33 1999.
This page generated on Wed Apr 7 10:50:39 1999 by SiteWeaver. Validate this page's HTML.
Contact our webmaster at rebelsky@math.grin.edu