Java Reference
In-Depth Information
PollerThread since that is the object that makes the retrieveData() call.
Since the observers are shown as standalone classes without any associations
to any other classes, that route of communication is not shown in the class
diagram.
17.4 More client details
Once the basic design is understood, we can begin to fill in some of the missing
details. SimClient is the first object instantiated by the main() method of the
client application, and it creates all the other objects as needed. One of the first
things that SimClient must do is contact the ServerFactory to obtain a
reference to the Server .Weassume that the ServerFactory object already
pre-exists on the remote server machine. For completeness, we show those asso-
ciations in the next version of the client class diagram, though they don't really
add much to what we must know in order to implement the client classes.
We also explicitly show the InputPane class that collects the user's input
data. For organizational reasons, it is convenient to collect the input pane class and
the two (or more) observer classes as subcomponents of a DisplayManager
class that manages all user input and display functions. It is this DisplayMan-
ager and its subcomponents that present the GUI to the user.
It is also convenient to collect all interactions with the server into a central
location which we call the ServerGateway class. Any class that needs to call a
server method does so through the server gateway, meaning that only the server
gateway needs a reference to the server class. In that way, any changes to the
server interface will need to be dealt with only in the gateway class instead of
spread over several client classes. The one exception might be the poller thread
class which makes frequent calls to retrieveData() on its own schedule. To
avoid function-call overhead for such frequent server calls, it may be advisable
to permit PollerThread to call the server directly rather than going though
ServerGateway .
While we now have a good handle on the client design, perhaps a collaboration
diagram will be helpful to understand the order and flow of messages in the client.
Having the collaboration diagram handy also serves as a reference when we start
writing actual Java code to implement the client. Therefore we present the diagram
in Figure 17.2.
Here we can see that SimClient first obtains a server from the server factory,
as explained in Chapter 16, and then initializes the server. At first glance, this
initialization might be thought unnecessary since initialization could occur when
the server factory creates the server. However, a separate initialization step is
more general and permits the factory, for instance, to keep a pool of inactive
uninitialized servers instead of constructing a brand new server for each
client. At sequence 3, SimClient instantiates the DataManager , passing a
reference to the server. DataManager then instantiates the PollerThread ,
Search WWH ::




Custom Search