firstName = empFirstName;
public String getFirstName()
public void setLastName(String empLastName)
lastName = empLastName;
public String getLastName()
Listing 2-14 reveals that the name field has been removed in favor of new
firstName and lastName fields, which were added to improve performance. Be-
cause setFirstName() and setLastName() willbecalledmorefrequentlythan
setName() ,andbecause getFirstName() and getLastName() willbecalled
morefrequentlythan getName() ,itismoreperformant(ineachcase)tohavethefirst
twomethodsset/get firstName 'sand lastName 'svaluesratherthanmergingeither
value into/extracting this value from name 's value.
Listing 2-14 also reveals setName() calling setFirstName() and
setLastName() , and getName() calling getFirstName() and
getLastName() , rather than directly accessing the firstName and lastName
imagine another implementation change that adds more code to setFirstName() ,
setLastName() , getFirstName() , and getLastName() ; not calling these
methods will result in the new code not executing.
Client code (code that instantiates and uses a class, such as Employee ) will not
break when Employee 's implementation changes from that shown in Listing 2-13 to
that shown in Listing 2-14 , because the original interface remains intact, although the
implementation, especially the name field.