- Forward


Discussion of Programming Assignment 3


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu

Print

AbstractEditableReadingWorker
Back SMYC Forward
edu/jmu/cs/academics/document/AbstractEditableReadingWorker.java
 
AbstractDocumentAction
Back SMYC Forward
edu/jmu/cs/academics/document/actions/AbstractDocumentAction.java
 
AbstractOpen
Back SMYC Forward
edu/jmu/cs/academics/document/actions/AbstractOpen.java
 
Quit
Back SMYC Forward
edu/jmu/cs/academics/document/actions/Quit.java
 
AbstractModalDialog
Back SMYC Forward
edu/jmu/cs/academics/gui/AbstractModalDialog.java
 
BackgroundTaskDialog
Back SMYC Forward
edu/jmu/cs/academics/gui/BackgroundTaskDialog.java
 
AbstractLocalizedAction
Back SMYC Forward
edu/jmu/cs/academics/gui/actions/AbstractLocalizedAction.java
 
FileTypeFilter
Back SMYC Forward
edu/jmu/cs/academics/io/FileTypeFilter.java
 
StringReadingWorker
Back SMYC Forward
edu/jmu/cs/academics/io/StringReadingWorker.java
 
OpenString
Back SMYC Forward
edu/jmu/cs/academics/io/actions/OpenString.java
 
Interfaces
Back SMYC Forward
  • From a design perspective, what is the benefit of interfaces?
    • Polymorphism - They allow an object of one type to appear to be of another type (e.g., when being passed to a method).
      Expand
  • Where have interfaces been particularly useful in the current design?
    • They define the capabilities of Editable objects and EditableFactory objects, allowing us to work with any number of different kinds of "documents"
      Expand
Abstract Classes
Back SMYC Forward
  • From an implementation perspective, what is the benefit of abstract classes?
    • They can be used to eliminate duplicate code across related classes.
      Expand
  • From a design perspective, what are two reasons for making a parent class abstract?
    • Conceptual - An instance doesn't fit in with our understanding of the world
      Expand
    • Pragmatic - The class has one or more abstract methods
      Expand
  • From a design perspective, what are the benefits of abstract methods?
    • They can be invoked by other methods in the class (which effectively leads to code in the parent class executing code in the child class) of the world
      Expand
Extending an Abstract Class with an Abstract Class
Back SMYC Forward
  • Why is AbstractLocalizedAction included in the design?
    • It adds localization capabilities to AbstractAction.
      Expand
  • Why is it abstract?
    • Because it doesn't implement actionPerformed(), each specialization needs to do that.
      Expand
Extending an Abstract Class with an Abstract Class (cont.)
Back SMYC Forward
  • Why is AbstractDocumentAction included in the design?
    • It adds capabilities to AbstractLocalizedAction (specifically, setting the DocumentManager).
      Expand
  • In the current design, can it be used to add capabilities to AbstractAction?
    • No, because it extends AbstractLocalizedAction.
      Expand
  • How might the design be changed to allow capabilities to be added to both?
    • We could use the Decorator Pattern, but since most applications will be localized, this seems like "over design".
      Expand
Extending an Abstract Class with an Abstract Class (cont.)
Back SMYC Forward
  • Why is AbstractOpen included in the design?
    • It adds capabilities to AbstractDocumentAction. Specifically, it creates and controls the BackgroundTaskDialog and it is a PropertyChangeListener.
      Expand
  • Why is it abstract?
    • Because concrete specializations need to implement createReader() (since the AbstractEditableReadingWorker varies with the source.
      Expand
  • With all of this, how much effort is required to create a concrete specialization (e.g., OpenString)?
    • Almost none - createReader() contains one line of code.
      Expand
Extending an Abstract Class with an Abstract Class (cont.)
Back SMYC Forward
  • Why is AbstractEditableReadingWorker included in the design?
    • It adds capabilities to SwingWorker that are needed by every class that needs to read an Editable.
      Expand
  • Why is it abstract?
    • Because how the reading must be done varies with the type of the Editable (which will be implement in the concrete specializations).
      Expand
  • Why was the abstract method readInCallersThread() included when the children are required to implement doInBackground()?
    • Because this enables the work to be done either in a background thread (which will normally be the case) or in another thread (e.g., when testing).
      Expand
  • Why is this method declared to be abstract?
    • It is declared so that it can be invoked in the abstract class. It is declared to be abstract to that it doesn't have to be implemented in the abstract class but must be implemented by specializations.
      Expand
  • Why isn't doInBackground() implemented in this class?
    • It probably should be.
      Expand
Nested Classes
Back SMYC Forward
  • Why was TimeoutTask included in the design?
    • The java.util.Timer class needs to be passed a TimerTask to execute (and TimeoutTask extends TimerTask.
      Expand
  • Why is TimeoutTask a nested class?
    • Because it will only ever be used inside of BackgroundTaskDialog.
      Expand
  • Why is it an inner class?
    • Because it is associated with an instance of TimeoutTask and needs access to its SwingWorker (so that it can cancel it)
      Expand
Progress Bars
Back SMYC Forward
  • Why are progress bars hard to implement correctly?
    • You need a good estimate of the initial "size" and a way to measure progress.
      Expand
  • What's involved with using a progress bar for reading a file?
    • Knowledge of the size of the file and information about the percentage of the file that has been read. Also, since the user thinks of progress in units of time, a way to associate size and time (perhaps dynamically).
      Expand
  • In your experience, how good are progress bars?
    • Bad!
      Expand
Designing within Constraints
Back SMYC Forward
  • Why did the FileTypeFilter class extend javax.swing.filechooser.FileFilter and java.io.FileFilter?
    • Because the Java API has both, one for use within a GUI and one for use elsewhere.
      Expand
  • How could they have made things easier for us?
    • Have the more complicated interface extend the simpler one.
      Expand
Benefits of an Application Framework
Back SMYC Forward
  • Will we need to write any other Quit actions?
    • No, this one should work for all applications.
      Expand
  • Will we need to write any other Open actions?
    • Yes, for every didn't kind of source. However, each one will be very simple.
      Expand
  • What code is in the main class BigPixel? In other words, what does an application need to do?
    • Construct the relevant actions, construct and layout the GUI, construct the editor, construct the DocumentManager, and associate the editor and DocumentManager.
      Expand
There's Always More to Learn
Back -