Two Types of Roster!
- Criticize design decisions for a simple type hierarchy in Java made by employing the inheritance mechanism.
Recall the Roster class from previous chapters!
public class Roster {
private Student[] students;
private int numStudents;
public Roster(int size) {
students = new Student[size];
numStudents = 0;
}
public void add(Student s) {
// stub
}
public void remove(Student s) {
// stub
}
public Student find(String email) {
return null; //stub
}
}
Consider the following scenarios:
-
For courses at JHU, we search more frequently than we add/remove students. Therefore, we define
JhuRostersuch that itsfindimplements binary search. Theaddandremovemethods shall keep the underlying (students) data sorted to facilitate the binary search process. -
For MOOCs (Massive Online Open Courses) offered by "JHU Engineering for Professionals," we add/remove students much more frequently than we perform searching. Therefore, we define
MoocRostersuch that itsfindmethod implements linear search. Furthermore, theaddandremovemethods do not bother keeping the underlying (students) data sorted.
We asked students to implement JhuRoster and MoocRoster, and here are some of the design decisions they have made:
MoocRosterextendsJhuRoster(or the other way around)JhuRosterandMoocRosterare entirely different data types (or "data structures" if you like).- There is a
Rosterclass where bothMoocRosterandJhuRosterextend.
We will critique each design in the following section.