Java Reference
In-Depth Information
3. Enter lines 124 through 132 as shown in Figure 9-25 on the previous
page.
TextPad displays the isExpiring() method, the pseudo-accessor method for
the Password class (Figure 9-28). This method evaluates two conditions
and then returns a boolean value based on the result of the evaluation.
is prefix acceptable when
returning type boolean
if statement tests
two conditions
pseudo-accessor
method
returns computed
value, not actual
instance variable value
FIGURE 9-28
The requirements document in Figure 9-2 on page 541 requires several addi-
tional methods to be coded, including the set() method called earlier. Before
coding these methods, it is important to understand why some methods have
public access and others have private access and when to use them.
Understanding When to Use public
and private Methods
Eleven methods have been coded for the Password class, including seven accessor
methods and four mutator methods. The class diagram in Figure 9-3 on page
542 indicates that an additional four instance methods are needed to complete
the Password class, including the set() method, which is called in each of the
overloaded constructors to create new ArrayList objects.
As previously discussed, methods that users can access directly are, therefore,
part of the public interface and must be public. Those methods which are
designed for use only within the class should be private. In the Password class,
the set() method should be public, as it is called when a user wants to set a new
password value, whether by adding a new password or changing an existing pass-
word. The validate() method also must be public to allow user programs to
access its functionality.
The principal use of a password is to limit access to valid users only.
Programs using a Password object have the responsibility for validating users and
granting access, as certain users may be granted access to other user accounts
without providing the current user password. An example of this would be a
superuser, who requires access to various accounts for administrative purposes.
When a user program needs to validate whether a password matches the current
password, the Password object itself is responsible for doing the validation.
 
Search WWH ::




Custom Search