Chapter 10. Basic Inheritance

In This Chapter

  • Understanding inheritance

  • Implementing inheritance

  • Understanding the connection between inheritance and polymorphism

In Chapter 9, you create a Transaction object and use a switch statement to manage more than one kind of transaction in a single array. The problem with that approach is that the switch statements can rapidly get very complicated, and a program with switch statements scattered throughout becomes difficult to extend and enhance.

Quite frankly, this kind of complex control structure is characteristic of the procedural program paradigm that I speak of in Chapter 3. Object-oriented programming and Objective-C do not "improve" this control structure as much as eliminate it as much as possible. The way this is done is by using one of those Objective-C's extensions to C — inherence to take advantage of polymorphism (which I explain in Chapter 3). As you find out as I lead you through implementing an inheritance-based class structure in this chapter, this greatly simplifies things, and you end up with a program that is a great deal easier to understand and extend (the two actually go hand in hand).

Note

Once you get into the rhythm of thinking this way, programming and making changes becomes more fun and less dreary. You introduce fewer bugs as you add functionality to your program, and your coding becomes completely focused on the new functionality instead of having to go back through everything you have done to see if you are about ...

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.