Two Types of Roster!
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
JhuRoster
such that itsfind
implements binary search. Theadd
andremove
methods 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
MoocRoster
such that itsfind
method implements linear search. Furthermore, theadd
andremove
methods 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:
MoocRoster
extendsJhuRoster
(or the other way around)JhuRoster
andMoocRoster
are entirely different data types (or "data structures" if you like).- There is a
Roster
class where bothMoocRoster
andJhuRoster
extend.
We will critique each design in the following section.