< Previous | Contents | Next >
Game objects are often composed of other objects. For example, in a racing game, a drag racer could be seen as a single object composed of other individual objects, such as a body, four tires, and an engine. Other times, you might see an object as a collection of related objects. In a zookeeper simulation, you might see the zoo as a collection of an arbitrary number of animals. You can mimic these
287
288 Chapter 9 n Advanced Classes and Dynamic Memory: Game Lobby
kinds of relationships among objects in OOP using aggregation—the combining of objects so that one is part of another. For example, you could write a Drag_Racer class that has an engine data member that’s an Engine object. Or, you could write a Zoo class that has an animals data member that is a collection of Animal objects.