Java Reference
In-Depth Information
If we examine all the methods of AddressBook , we find that there are other places where we
could make similar improvements:
The addDetails method should check that its actual parameter is not null .
The changeDetails method should check both that the old key is one that is in use and that
the new details are not null .
The search method should check that the key is not null .
These changes have all been implemented in the version of the application to be found in the
address-book-v2g and address-book-v2t projects.
Exercise 12.14 Why do you think we have felt it unnecessary to make similar changes to
the getDetails and keyInUse methods?
Exercise 12.15 In dealing with parameter errors, we have not printed any error messages.
Do you think an AddressBook should print an error message whenever it receives a bad
parameter value to one of its methods? Are there any situations where a printed error message
would be inappropriate? For instance, do error messages printed to the terminal seem appro-
priate with the GUI version of the project?
Exercise 12.16 Are there any further checks you feel we should make on the parameters of
other methods, to prevent an AddressBook object from functioning incorrectly?
Server-error reporting
Having protected a server object from performing an illegal operation through bad parameter
values, we could take the view that this is all that the server writer needs to do. However, ide-
ally we should like to avoid such error situations from arising in the first place. Furthermore,
it is often the case that incorrect parameter values are the result of some form of programming
error in the client that supplied them. Therefore, rather than simply programming around the
problem in the server and leaving it at that, it is good practice for the server to make some effort
to indicate that a problem has arisen, either to the client itself or to a human user or program-
mer. In that way, there is a chance that an incorrectly written client will be fixed. But notice that
those three “audiences” for the notification will often be completely different.
What is the best way for a server to report problems when they occur? There is no single answer
to this question, and the most appropriate answer will often depend upon the context in which
a particular server object is being used. In the following sections, we shall explore a range of
options for error reporting by a server.
Exercise 12.17 How many different ways can you think of to indicate that a method has
received incorrect parameter values or is otherwise unable to complete its task? Consider as many
different sorts of applications as you can—for instance: those with a GUI; those with a textual
interface and a human user; those with no sort of interactive user, such as software in a vehicle's
engine-management system; or software in embedded systems such as a cash machine.
Search WWH ::

Custom Search