Java Reference
In-Depth Information
24. // Sets the first name to the given value.
public void setFirstName(String firstName) {
this.firstName = firstName;
}
// Sets the last name to the given value.
public void setLastName(String lastName) {
this.lastName = lastName;
}
// Sets the middle initial to the given value.
public void setMiddleInitial(char middleInitial) {
this.middleInitial = middleInitial;
}
25. Encapsulation allows you to change a class's internal implementation without
changing its external view to clients. When a class is encapsulated, clients cannot
directly access its fields, so changing those fields will not disturb client behavior
as long as the external view (method behavior) is consistent.
26. Cohesion describes how well a class's contents go together. You can tell that a
class is cohesive when each of its fields stores an important state related to the
object and each method interacts with that state in some way to produce useful
behavior.
27. We did not place console I/O code into our Stock class because doing so would
force clients to use those exact I/O messages. By keeping I/O code out of Stock ,
we kept it independent from its clients.
28. // Returns this Stock's symbol value.
public String getSymbol() {
return symbol;
}
// Returns this Stock's total number of shares purchased.
public int getTotalShares() {
return totalShares;
}
// Returns this Stock's total cost for all shares.
public double getTotalCost() {
return totalCost;
}
 
Search WWH ::




Custom Search