Chapter 3. An introduction to objects

 

This chapter covers

  • The concepts of objects, classes, and instances
  • Class hierarchies, inheritance, and polymorphism
  • Foundation Kit
  • The NSString class

In Objective-C the use of object-oriented programming is optional. Because Objective-C is based on a C foundation, it’s possible to use C-style functions (as evidenced by calls to NSLog in the previous chapter), but Objective-C’s full power is unlocked only if you make full use of its object-oriented extensions.

In this chapter we reveal some of the benefits of object-oriented development by covering how the NSString class, provided by Foundation Kit, can improve your productivity while increasing the robustness of any code that interacts with text.

Before we go too far in depth on that particular topic, let’s first take a look at the most basic concepts of object-oriented programming.

3.1. A whirlwind tour of object-oriented programming concepts

In this chapter we can’t do justice to every concept associated with object-oriented programming (also termed OOP, for short). Instead, the goal of this chapter is to make sure you have a solid understanding of the fundamental concepts and benefits of object-oriented programming and a working knowledge of the terminology. Throughout this book, we discuss object-oriented programming concepts as they apply to Objective-C and expand on what’s covered in this chapter. Let’s get started by learning what’s so wrong with C.

3.2. The missing data type: id

3.3. Pointers and the difference between reference and value types

3.4. Communicating with objects

3.5. Strings

3.6. Sample application

3.7. Summary