Lab: Questions About Abstract Classes and Interfaces


Name:                              Email:                   JAC#:


Part 1. Basics





1.2. 
    What methods are required of classes that implement the
    Comparator interface?
  
    





1.3. 
    The DirectoryComparator class will compile
    without error even though it doesn't implement the
    equals(Object) method required by the
    Comparator interface.  Why?
  
    





1.4. 
    The DirectoryComparator class is abstract.  
    What does that mean?
  
    





1.5. 
    What method(s) in the  DirectoryComparator class
    must be implemented by concrete children?
  
    





1.6. DirectoryNameComparator extends DirectoryComparator.  
    What method must it implement (in order to be concrete)?
  
    





1.7. 
    Does the DirectoryNameComparator
    implement the Comparator interface?
  
    





1.8. 
    In the main() method of the DirectorySorter 
    class, the variable comparatorToUse is declared
    to be a Comparator.  Why is it possible
    to assign a DirectoryNameComparator or
    a DirectoryDateComparator to 
    comparatorToUse?
  
    





1.9. 
    When the DirectorySorter is executed with no command-line
    arguments, the compare(Object, Object) message 
    is sent to  comparatorToUse by Arrays.sort().
    Trace the methods that are executed as a result of this message.
    [Note: For each step, list the signature of the method 
    that is called and the class it is in.]

    


Part 2. Design Issues





2.1. 
    What useful behavior/functionality do concrete children inherit
    from DirectoryComparator?
  
    





2.2. 
    Why does it make sense to have an abstract DirectoryComparator
    class?  In other words, why shouldn't we just include the 
    compare(Object, Object) method in the 
    DirectoryDateComparator class?
  
    





2.3. 
    The DirectorySorter class contains a
    containsSwitch method.  Why must this method
    be static?
  
    





2.4. 
    Draw a UML class diagram that shows the relationship between
    java.lang.Comparator,
    DirectoryComparator,
    DirectoryDateComparator,
    DirectoryNameComparator, and 
    java.lang.Object.
    (NOTE: You do not have to submit your answer to this question.)
  
    


Part 3. More Design Issues





3.2. 
    Why is it a good idea to include the TwoPartMeasure
    class in this design?  In other words, what would be bad about omitting
    the  abstract TwoPartMeasure class?
  
    





3.3. 
    Concrete subclasses of TwoPartMeasure must have an
    initializeUnits() method.  What must be done in this method?

    





3.4. 
    Why is this abstract method included in TwoPartMeasure
    (rather than, for example, simply including a comment that says 
    all subclasses must have such a method)?

    





3.5. 
    Syntactically, why must the TwoPartMeasure class 
    be declared abstract?
  
    





3.6. 
    Conceptually, why should the TwoPartMeasure class 
    be declared abstract?

    





3.7. 
    Why is it a good idea to include the Comparable
    interface in this design?
  
    





3.8. 
    In this design, how are TwoPartMeasure and 
    HolidayAccount related?
  
    





3.9. 
    Why doesn't it make sense to have HolidayAccount
    extend TwoPartMeasure?