OOP » Aggregate Objects »

 

Aggregate Objects

Table Of Contents
Objects which contain data are composed of other objects. For example, the Point class (point.py) presented earlier consists of two integer objects representing the x- and y-coordinates. If create two Point objects

pointA = Point( 5, 7 )
pointB = Point()
 

the result graphically would be as shown below

Attach:(Defining Classes/ptobjects.png)

Object Composition

The two string fields are reference variables since strings are objects. When the \class{Student} object is created, the data fields become aliases of the strings passed to the constructor.

\begin{define}[aggregate object] an object composed, in part, of other objects; it contains data fields which are references to other objects. \end{define}

\subsection{The Address Class}

Consider the \class{Address} class below which defines an object representing a person’s mailing address. The class does not contain many useful methods at this time, however, it does provide another class example.

Table Of Contents

© 2006 - 2008: Rance Necaise - Page last modified on September 21, 2006, at 10:02 PM