OOP » Object Composition »


Object Composition

Operator Overloading Table Of Contents Exceptions

Class Relationships

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.

Mutable Objects

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.

an object whose state cannot be changed once it is created. In Python, the numeric, boolean, and string types are all exampls of immutable objects.
an object whose state can be changed after it is created. That is, one or more data fields of the object can be changed by at least one method of the class. Examples include the 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.

Operator Overloading Table Of Contents Exceptions

© 2006 - 2008: Rance Necaise - Page last modified on September 30, 2006, at 06:20 PM