Large programs and software libraries typically contain many classes. These classes can have various types of relationships. The three most common ones include: uses, has-a, and is-a.
In a uses relationship, one class depends on another in order to carry out a particular operation. This dependency can exist between different classes are among the same class. With a has-a relationship, the objects of one class contains objects (as data fields) of one or more other classes. The Point
class defined in an earlier chapter contained two numeric objects. Thus, we would say, the Point
class has two numbers. Finally, the is-a relationship exists between objects when one class is derived from another class. The is-a relationship will be discussed later with Class Inheritance.
Any object that stores information is said to have a state. The object’s state is the current set of values that it contains. Objects are divided into two distinct categories: mutable and immutable.
Point
and Student
classes from the earlier chapter.
If there are no methods defined for a class which alter the data fields, the class is said to be an immutable close. Otherwise, it is mutable.