Chapter 5. Relationships Between Objects

As you saw in Chapter 4, any two objects can have a "fleeting relationship" based on the fact that they invoke methods on each other, in the same way that two strangers passing on the street might say "Hello!" to one another. We call such relationships between objects behavioral relationships because they arise out of the behaviors, or actions, taken by one object X relative to another object Y. With behavioral relationships, object X is either temporarily handed a reference to object Y as an argument in a method call or temporarily requests a reference to Y from another object Z. However, the emphasis is on temporary; when X is finished communicating with Y, object X often discards the reference to Y.

In the same way that you have significant and more lasting relationships with some people (family members, friends, colleagues, and so forth), there is also the notion of a more permanent relationship between objects. We refer to such relationships as structural relationships because in order to keep track of such relationships, an object actually maintains lasting references to its related objects in the form of fields, a technique that we discussed in Chapter 3.

In this chapter, you'll learn

  • The various kinds of structural relationships that may exist between classes and between individual objects, and how we characterize them

  • How through a powerful mechanism called inheritance we can derive new classes by describing only how they differ from existing classes

  • The rules for what we can and can't do when deriving classes through inheritance

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset