Chapter 3
Containment and Composition

We saw in the previous chapter that all material objects, except the elementary particles, are composed of other material objects. We’ll take a closer look at how composition works, but first we’ll look at the idea of objects that contain other objects without being composed of them. Once again, one of our goals is to recover the ordinary meanings of words that have been overloaded with technical meanings.

Containment

Suppose I go to a grocery store and buy a dozen eggs. I carry the eggs home in a carton that is made of Styrofoam, fiberboard, or some other material that protects the fragile eggs from breaking. Over the course of a week I eat the eggs, and when the last egg is gone I throw away the carton.

Each egg is an object—a material thing—and the carton is an object, but they are different kinds of objects. The carton was specially designed to hold up to twelve eggs. The carton is a container and the eggs are its contents. When I brought the carton home it was full. As soon as I took the first egg out of the carton it was no longer full. Once I took the last egg out of the carton it was empty. So the state of the container—full, partially full, empty—varied over the course of the week. However, despite its changing state, the composition of the carton never changed. I would never at any time say that the carton was composed of eggs. It was composed of Styrofoam or fiberboard.

In general, a container is designed so that contents can easily be added and removed. These operations change the state of the container, but do not change its composition—that is, what it is made of. If I took a few eggs out of the carton and made a cake from them, it would be correct to say that the eggs were in the cake, but not in the same sense as being in the carton. In the cake the eggs have lost their integrity and can never be removed from it again. Unlike the egg carton, the cake is composed of eggs, and flour and milk and sugar and other ingredients, blended together.

Observe that containment is exclusive, in two senses. First, an egg is either in a carton or not in a carton. It cannot be partially contained. Second, if I had another egg carton, it would be impossible for me to have a particular egg in both cartons simultaneously.

Some containers can nest, like Russian matryoshka dolls. Each container can contain, not only whatever fits, but also another, smaller container, which can contain another smaller container, and so on. With nesting containers, it is possible to say that something in a smaller container is also in the larger container that contains the smaller container, but the contents of the smaller container are not in the large container directly. An object can only be directly in one container at a time. If the carton of eggs is in a grocery bag, we can say that the eggs are in the bag, but it is more complete to say that the eggs are in the carton in the bag.

Suppose I bring home the dozen eggs from the grocery store, in their protective container, but my refrigerator is so full that I cannot fit the carton of eggs inside. To solve the problem, I remove the eggs from the carton, tuck each of the twelve eggs into little spaces that can accommodate an egg-sized object, and throw the carton away. Even though I have destroyed the container, the twelve eggs continue to exist in the refrigerator. This shows that, in ordinary parlance, a container and its contents can exist independently.

Composition

We saw in the previous section that containment is not composition; that is, a container is not composed of its contents. We also saw one kind of composition, where a cake is composed of its ingredients blended together in such a way that they can’t be separated again. There are a few more modes of composition—ways in which objects can be composed of smaller objects—that are relevant to our ultimate purpose of representing data, software, and semantics.

Remember that an object is composed of other objects in some kind of relatively static spatial relationship. Certainly a cake is an object, because it is composed of eggs, milk, flour, sugar, and other objects in a relatively static spatial relationship: they are all blended together and will remain that way until the cake is consumed.

Now let’s think about a frosted cake. Frosting is applied to the top of the cake and between the layers. This isn’t quite blending, because the integrity of the cake and the frosting is still preserved. You can still see the difference between them, though it would be difficult to separate them once again. This kind of object composition is called aggregation. An object is formed from other objects in a way that the components keep their integrity, but it would be difficult to extract the components after they’ve been joined together.

For those who know the UML, please note that, in ordinary English and in COMN, composition is the over-arching term, and aggregation is one particular kind of composition. Likewise, a component is that which is part of any kind of a composite.

For those who are familiar with dimensional modeling, please note that what is called aggregation in that discipline is blending in ordinary English and in COMN.

In contrast to aggregation, we can have assembly. This is a mode of composition where components retain their integrity and can even be removed from the object which they compose, if so desired. A real-world example of an assembly is an engine. Its parts are connected with screws and other connectors that can be disconnected and reconnected at will.

Another important mode of composition is juxtaposition, where objects are arranged in a fixed spatial relationship to each other without being blended and without being connected to each other. For instance, dinner plates and silverware are juxtaposed on a dining table to form a place setting.

Regardless of the mode of composition, we call the objects of which another object is composed its components. So, the components of a (blended) cake are its ingredients, the components of a layer cake are alternating layers of cake and frosting, the components of an engine include pistons, spark plugs, valves, the block, etc., and the components of a place setting include dishes, silverware, and glasses.

Components are not contents. For instance, the engine assembly, which is composed of many components, will eventually contain gasoline, but we would never say that the engine is composed of gasoline. The soup bowl will eventually contain soup, but we would never say that the place setting is composed of soup.

In any given real-world object, it is likely that many modes of composition are present at once. For example, one of the components of an engine assembly is a spark plug. A spark plug is an aggregation of ceramic and metal parts joined together such that one can see the different parts but one cannot separate them (without destroying the spark plug and its parts).

Key Points

  • A container is an object that can hold other objects in such a way that they can be easily added to and removed from the container.
  • Adding objects to and removing objects from a container changes the container’s state but not its composition. We never say that a container is composed of its contents.
  • Containment is exclusive. An object can only be in one container at a time, and is either entirely in or entirely out of the container.
  • Containers can nest: A container may contain another container.
  • All objects, except the elementary particles, are composed of other objects.
  • Four modes of composition important to us are:
    • juxtaposition
    • blending
    • aggregation
    • assembly
  • In any given real-world object, it is likely that many modes of composition are present at once.

Chapter Glossary

container : an object that can contain other objects (like an egg carton)

contents : the objects inside a container (like the eggs in an egg carton)

juxtaposition : arranging objects in a fixed spatial relationship without connecting them (like a place setting)

blending : combining two or more objects in such a way that they lose their integrity (like eggs, flour, milk, and sugar in a cake)

aggregation : combining two or more objects in such a way that they retain their integrity, but it is difficult or impossible to separate them again (like a layer cake)

assembly : combining two or more objects in such a way that they retain their integrity, and it is relatively easy to separate them again (like an engine)