Objective-C Inheritance

From Techotopia
Revision as of 19:51, 21 October 2009 by Neil (Talk | contribs) (New page: In the chapter entitled An Overview of Objective-C Object Oriented Programming we covered the basic concepts of object-oriented programming and worked through an example of creating a ...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

In the chapter entitled An Overview of Objective-C Object Oriented Programming we covered the basic concepts of object-oriented programming and worked through an example of creating a new class using Objective-C. In that example, our new class was derived from the NSObject base class and as such inherited a number of traits from that parent class. In this chapter we will explore the subject of inheritance in greater detail.

Inheritance, Classes and Subclasses

The concept of inheritance brings something of a real-world view to programming. It allows a class to be defined which has a number of characteristics and then other classes to be created which are derived from that class. The derived class inherits all of the features of the parent class and typically then adds some features of its own.

By deriving classes we create what is often referred to as a class hierarchy. The class at the top of the hierarchy is known as the base class or root class and the derived classes as subclasses or child classes. Any number of subclasses may be derived from a class. The class from which a subclass is derived is called the parent class.

Classes need not only be derived from a root class. For example, a subclass can also inherit from another subclass with the potential to create large and complex class hierarchies.