After you've instantiated an object, its inherited behavior is determined by its place in the class hierarchy, but it may also be part of a containment hierarchy: that is, it can contain and be contained by other objects. Containment relationships are also called "has a" relationships. For example, a window that contains a text object "has a" text object. The text object might in turn contain graphics or multimedia objects, and the window that contains it is in turn contained within a particular application.
Grady Booch (1994) describes this combination of class and containment hierarchies as "the canonical form of a complex system." It turns out that an amazing variety of artificial and natural structures, from cells to spacecraft, can be modeled by using similar complementary hierarchies. Virtually anything in the real world can be described both as "part of" something else and as one instance of a category of related things.
For example, an individual cardiac cell is part of a heart, which is part of a
circulatory system, which is part of a body made up of many complex
interdependent systems. At the same time, a cardiac cell is one of three basic
kinds of muscle cells--cardiac, smooth, and striated--and it has some properties
in common with those kinds of cells and some properties that are different.
Similarly, a valve is part of a car engine, which is part of a car, and the valve
itself is made up of still smaller parts. A valve can also be described as a
particular kind of valve that resembles other valves in some ways and differs
from them in other ways.
This natural correspondence between the hierarchical yet flexible relationships
among classes and the relationships we perceive in the real world give OOP its
unique ability to model or simulate complex systems.
[Contents]
[Previous]
[Next]