O'Reilly logo

Learn Objective-C on the Mac: For OS X and iOS, Second Edition by Scott Knaster, Waqar Malik, Mark Dalrymple

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 5

Composition

In the previous chapter, you got hip to inheritance, a way to set up a relationship between two classes that removes the need for a lot of duplicated code. And we (briefly) mentioned that you can also set up relationships using composition, which is the subject of this chapter. You can use composition to combine objects so they can work together. In a typical program, you’ll use both inheritance and composition when creating your own classes, so it’s important to have a good handle on both concepts.

What Is Composition?

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required