Discussion of Programming Assignment 3
|
Prof. David Bernstein
James Madison University
|
|
Computer Science Department
|
bernstdh@jmu.edu
|
AbstractEditableReadingWorker
edu/jmu/cs/academics/document/AbstractEditableReadingWorker.java
AbstractDocumentAction
edu/jmu/cs/academics/document/actions/AbstractDocumentAction.java
AbstractOpen
edu/jmu/cs/academics/document/actions/AbstractOpen.java
Quit
edu/jmu/cs/academics/document/actions/Quit.java
AbstractModalDialog
edu/jmu/cs/academics/gui/AbstractModalDialog.java
BackgroundTaskDialog
edu/jmu/cs/academics/gui/BackgroundTaskDialog.java
AbstractLocalizedAction
edu/jmu/cs/academics/gui/actions/AbstractLocalizedAction.java
FileTypeFilter
edu/jmu/cs/academics/io/FileTypeFilter.java
StringReadingWorker
edu/jmu/cs/academics/io/StringReadingWorker.java
OpenString
edu/jmu/cs/academics/io/actions/OpenString.java
Abstract Classes
-
From an implementation perspective, what is the benefit of
abstract classes?
-
They can be used to eliminate duplicate code across related classes.
-
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
-
Pragmatic - The class has one or more abstract methods
-
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
Extending an Abstract Class with an Abstract Class (cont.)
-
Why is
AbstractDocumentAction
included in the design?
-
It adds capabilities
to AbstractLocalizedAction
(specifically, setting
the DocumentManager
).
-
In the current design, can it be used to add capabilities
to
AbstractAction
?
-
No, because it extends AbstractLocalizedAction
.
-
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".
Extending an Abstract Class with an Abstract Class (cont.)
-
Why is
AbstractOpen
included in the design?
-
It adds capabilities
to AbstractDocumentAction
. Specifically, it creates and
controls the BackgroundTaskDialog
and it is a
PropertyChangeListener
.
-
Why is it abstract?
-
Because concrete specializations need to
implement createReader()
(since the
AbstractEditableReadingWorker
varies with the
source.
-
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.
Extending an Abstract Class with an Abstract Class (cont.)
-
Why is
AbstractEditableReadingWorker
included in the design?
-
It adds capabilities to SwingWorker
that are needed by
every class that needs to read an Editable
.
-
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).
-
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).
-
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.
-
Why isn't
doInBackground()
implemented in this class?
-
It probably should be.
Nested Classes
-
Why was
TimeoutTask
included in the design?
-
The java.util.Timer
class needs to be passed
a TimerTask
to execute (and TimeoutTask
extends TimerTask
.
-
Why is
TimeoutTask
a nested class?
-
Because it will only ever be used inside
of BackgroundTaskDialog
.
-
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)
Progress Bars
-
Why are progress bars hard to implement correctly?
-
You need a good estimate of the initial "size" and a way to
measure progress.
-
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).
-
In your experience, how good are progress bars?
-
Bad!
Benefits of an Application Framework
-
Will we need to write any other
Quit
actions?
-
No, this one should work for all applications.
-
Will we need to write any other
Open
actions?
-
Yes, for every didn't kind of source. However, each one will
be very simple.
-
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
.
There's Always More to Learn