A "Rich" Alternative for System i GUI Development
A previous blog entry "Java data queues 201 -- the thread side of a thread based console application view-controller for System i demonstration model" solved the problem of the java application being stuck waiting to read a data queue by putting the read data queue part of the program into a separate thread. Each time a data queue read occurs the thread fires a PropertyChangeEvent. The event contains the information read from the data queue.
This blog entry address the rest of the example application. A large part of the main() portion of this application, DtaQExample3#, is the same as Examples 1 and 2 in that they
- get input from the console and
- write it to the model input data queue
(remember that demo model running on the iSeries?). See the early discussion.
The different (new) parts of DtaQExample3# is that
- the model input data queue (read) is started as a thread (DtaQExample3Thread)
- PropertyChangeListener is implemented
Three examples (3a, 3b and 3c) show different ways to implement PropertyChangeListener so you can experiment with the differences.
DtaQExample3a implements PropertyChangeListener as a separate class.
DtaQExample3b implements PropertyChangeListener as an anonymous inner class.
DtaQExample3c implements PropertyChangeListener in its declaration and provides the methods of PropertyChangeListener
The PropertyChangeListener (PCL) in these examples listens for the PropertyChangeEvent (PCE) named "readDq". When it receives on it creates Strings from the data (Record) contained in the PCE and displays the Strings on the console.
If you look at the propertyChange() method of PCL in all the three examples you will see they are identical.
Example3a implements PCL as a separate class, DtaQExample3aListener. This isolates what is going on the in PCL from the rest of the application. You choose what to provide this class in the constructor design and the setter methods, and choose what to expose with the getter methods.
Example3b implements PCL as an anonymous inner class. An inner class is a separate class that has limited assess to data in the class which creates it and does not exist outside that class.
Example3c implements PCL in the class declaration, at the very top of the program. Because the Example3c class formally implements the PropertyChangeListener class it must provide the required method
public void propertyChange( PropertyChangeEvent event )
The method has full access to the class variables of Example3c and easily interacts with the rest of the class.
The choice of how to implement PropertyChangeListener depends on the design.
The advantages of a separate PCL class (3a) are
- it can be re-used
- it puts the PCL and what it does into a black box
The downside is more design work and coding is required.
The advantage of an inner class to implement PCL (3b) is that it is quick to write and can interact with the data in the parent class. It is a good choice if the inner class does very little and won't be reused.
The downside, at least for me, is that inner classes can be messy, hard to read and have a tendency to grow as the design changes.
The advantage of implementing PCL at the class level (3c) is that the work of the listener is put into the propertyChange() method and that method can easily communicate with the rest of the class.
I really don't see a downside when this approach fits with the design. That is the PCL is used only by, and communicates with, the one class which implements it.
Posted by Bill Blalock at April 21, 2007 1:00 PM

| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
We welcome your comments and opinions and encourage lively debate on the issues. However, Penton Media reserves the right to delete or move any content that it may determine, in its sole discretion, violates or may violate its Terms of Use or is otherwise unacceptable. For more information, see Penton Media's Terms of Use.