Java Reference
In-Depth Information
In this example, User and Password have a has-a relationship; that is, a User
has-a Password. Because the Password object is private to the User, the User class
handles all interaction with the Password object and must provide public meth-
ods for an application to validate or change a password.
Figure 10-35 displays the code for the User class. Line 9 includes the User
class header. Lines 11 and 12 declare two variables, name and pswd, to store the
user logon information. By incorporating a reference to a Password object as an
instance variable, line 12 illustrates the use of aggregation. Lines 14 through 30
include constructors for the User class.
FIGURE 10-35
(continued)
 
Search WWH ::




Custom Search