...
The program passes a boolean debug flag
to (TerminalIO
). The value of the flag is true iff the command line argument -d
or -debug
is passed to main
.
The GUI Interface
In principle, the GUI interface to the laundry simulation (implemented by SimLaundryApplication
and affiliated classes) could have been written as an alternate implementation of the IOProcess
interface. But in Java GUIs (and GUIs in other languages) essentially all code that accesses and updates GUI components must run in the event-handling thread of the Java Virtual Machine. When the program runs in TerminalIO
mode, the Main
class creates a student and runs the simulation (using the simluate
method in Student
) in the main thread. A GUI implementation of IOProcess
would have to install closures (called listeners or callbacks) in the Student
class that would run whenever the state of Acker's world changed (as displayed in the GUI window). The Student
class would have to be extended to include methods that accept such listeners and code to execute the appropriate listeners whenever the state of some object in Acker's world changed. But note that these listeners will run in the main thread unless the code in the listeners specifically addresses this issue. The listener code can send closures (technically anonymous classes implementing the Runnable
interface) to the event-handling thread using the methods invokeLater
and invokeAndWait
.
But for simple GUIs applications like this laundry simulation, it is often simpler to write the GUI as an application that is driven by GUI events. The initialization of the GUI creates an Acker Student object and associated DoCommandVisitor. Each GUI event triggers the execution of DoCommandVisitor; in some cases, such as reading input from a file, it triggers the execution of DoCommandVisitor on a stream of Commands. In essence, the event-handling loop built-in to the Java Swing framework is used to drive the computation rather than a separate loop in the main thread such as the one in the simulate
method in Student
. writing the GUI as an implementation of IOProcess
means the program has than a separate loop in the main thread such as the one in the simulate method in Student.
The GUI could also have been written as an implementation of the IOProcess interface. This approach, which conforms to the classic "model-view-controller" (MVC) pattern, is more flexible because it decouples the GUI (the view in MVC
terminology) from the model, but it is also more complex because it involves the cooperative execution of
two loops in separate threads--a main program loop in the simulate method of Student and the loop driving the
event-handling thread supporting the processing of GUI inputs. The SimLaundryApplication dispenses with the main program loop by absorbing the application (often called the model) into the GUI (often called the view),.
Efficiency
For this assignment, you should be concerned about relevant asymptotic efficiency. Choose the simplest representation that yields good performance on inputs of plausible size.
...