Interfaces
With Examples in Java |
Prof. David Bernstein
|
Computer Science Department |
bernstdh@jmu.edu |
abstract
modifier) terminated by a ;
min()
and max()
return the index
EmergencyMessage
Base Class Revisited
Alert
Derived Class Revisited
Prioritized
that does not Specialize EmergencyMessage
Note that this application uses an array of Prioritized
objects
(which can contain EmergencyMessage
objects, Alert
objects, and AccidentReport
objects).
B
contains all of the methods in the
interface A
(and more)B
specialize the
interface A
extends
and implements
?
Alert
extends
EmergencyMessage
and could implement
one or more interfacesAlert
realizes
the Prioritized
interface
Suppose we want to be able to find the AccidentReport
involving the largest number of vehicles.
compareTo()
method could
use the result of a call to getPriority()
rather than the size of the accidentcompareTo()
method could be moved
to the base EmergencyMessage
class and the
typecast would be to a Prioritized
and
a compareTo()
method would have to be added
to the AccidentReport
classPrioritized
interface extend the
Ordered
interface?compareTo()
methods in EmergencyMessage
and AccidentReport
? Should specialization be
used to eliminate this code duplication?