Chapter 6. Adding a Little More Class to Your Program

In This Chapter

  • Understanding objects and classes

  • Dissecting an object-oriented program

  • Defining the program interface

  • Implementing the interface

  • Examining the program logic

  • Using more than one source file

  • Getting the naming conventions

This chapter covers objects and classes and messages, and the difference between a program based on functions and global data and one based on objects. I show you quite a bit about the mechanics of using objects and classes in your program.

I also introduce you to some basic ideas about encapsulation. Encapsulation involves more than simply hiding instance variables behind the object's wall, as you'll see as you read this chapter and the rest of this book.

I also explain and illustrate some of the advantages of using objects, but to be frank, I only scratch the surface when it comes to that. As you continue through this book, I'll illustrate, and you'll discover on your own, many more.

Grasping Objects and Their Classes

In Chapter 5, I showed you what you would have to do to make your program easier to extend. You created two functions, spendDollars: and chargeForeignCurrnecy:, that used a pointer to a budget variable. You could then pass in the pointer to europeBudget or englandBudget depending on where you were (Europe or England), and the function would operate on the data for that country.

The program architecture you created looked like the following (I'm going to omit the function implementation for ...

Get Objective-C® For Dummies® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.