Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Composition in programming is like composition in music: you're bringing individual components together and making them work to build something bigger. In music, you might bring together a bassoon part and an oboe part in creating a symphony. In software, you might bring together a pedal object and a tire object as part of a virtual unicycle.
In Objective-C, you compose by including pointers to objects as instance variables. So, our virtual unicycle would have a pointer to a Pedal object and a pointer to a Tire object and would look something like this:
@interface Unicycle : NSObject
{
Pedal *pedal;
Tire *tire;
}
@end // Unicycle
Through composition, a Unicycle consists of a Pedal and a Tire.
NOTE