Java Reference
In-Depth Information
PROBLEM ANALYSIS The problem that the PasswordException class should
solve is to allow other programs to differentiate between the exceptions gener-
ated by the Password class for expired or invalid passwords. It also must allow a
common, generic reference to all password exceptions from the Password class.
The requirements document outlines several attributes and behaviors for the
PasswordException class and subclasses. The PasswordException class and sub-
classes must generate specific exceptions for expired passwords; invalid pass-
words (passwords that meet format requirements, but do not match the current
password value for the user); passwords with an invalid format (for example, a
password without a numeric character); passwords with an invalid size; pass-
words recently used; and passwords that encountered an internal error when
being stored in the password history. Additionally, all subclasses of
PasswordException must have a method that returns a short message indicating
the condition under which the exception is used.
The requirements document also specifies that any attempt to use an invalid
password should increment an internal count when an invalid password excep-
tion is generated. User programs must be able to obtain the value of this count,
as they will determine the number of invalid attempts allowed. Using a valid
password will reset the count to zero. Because the Password class determines
when a password is valid, a Password object is responsible for triggering the
resetting of the invalid password count back to zero.
The requirements document further specifies that when a password size
exception is generated, the exception object must provide the user program with
the following information: an error message, the current password size, maxi-
mum password size, and minimum password size at the time of the exception.
This information allows the user program to take the appropriate action.
Finally, the requirements document requires a multiple window application
to test the PasswordException classes. This application displays a single window
to the user at one time, hiding the window not in use.
DESIGN THE SOLUTION Once you have analyzed the problem and
understand the needs, the next step is to design the PasswordException class.
The purpose of creating the PasswordException class and its subclasses is to
allow a more specific identification of the kind of exception thrown so the user
program can take more appropriate action. Figure 10-3 shows an example of a
generalization hierarchy for the PasswordException class and subclasses. As you
learned in Chapter 1, a generalization hierarchy, or inheritance hierarchy , is an
object-oriented design tool used to show the relationships among classes and to
describe the inheritance relationships between classes. By convention, abstract
classes, interfaces, and abstract methods are shown in italics in a class diagram.
Search WWH ::




Custom Search