|
Grab a Piece of Paper! |
Given a list of attributes and behaviors for two classes:
- identify common attributes and behaviors that could be part of a superclass when creating a class hierarchy.
- list the remaining attributes and behaviors for the subclasses.
- name the superclass.
- write is-a statements for each class with the superclass.
- evaluate your is-a statements. Do they accurately represent the relationship? For example, "Student is-a Person"
Cars and Trucks
| Car |
Truck |
Superclass: Give it a name |
| Attributes |
| String brand |
String brand |
|
| String color |
String color |
|
| int year |
int year |
|
| int numberOfDoors |
double cargoCapacity |
|
| boolean hasSunroof |
boolean hasFourWheelDrive |
|
|
|
|
| Behaviors |
| start() |
start() |
|
| stop() |
stop() |
|
| displayInfo() |
displayInfo() |
|
| turnOnAirConditioning() |
turnOnAirConditioning() |
|
| openTrunk() |
loadCargo() |
|
|
unLoadCargo() |
|
Teacher and Custodian
| Teacher |
Custodian |
Superclass: Give it a name |
| Attributes |
| String name |
String name |
|
| int employeeId |
int employeeId |
|
| double hourlyRate |
double hourlyRate |
|
| String subject |
String assignedArea |
|
| int roomNumber |
boolean hasMasterKeys |
|
|
|
|
| Behaviors |
| clockIn() |
clockIn() |
|
| clockOut() |
clockOut() |
|
| displayEmployeeInfo() |
displayEmployeeInfo() |
|
| teachLesson() |
cleanArea() |
|
| gradeAssignments() |
lockBuilding() |
|