Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

6.1. Subclassing

In chapter 5, you learned how to create your own classes. If you look back, you’ll see that the classes you made, such as CTRentalProperty, are subclasses of NSObject. NSObject is the most basic class that Objective-C provides. You’ll subclass NSObject many times when creating original classes for your application. This isn’t to say it’s the only class you can subclass: any class in Objective-C can be extended by subclassing. NSObject is explored in more detail later in this chapter.

6.1.1. What is subclassing?

Subclassing is the act of taking a class, with all of its methods and instance variables, and adding to it. A classic example of subclassing logic is used in taxonomy, when classifying species. A human is a mammal; a tiger is a mammal as well. Tigers and humans can both be thought of as subclasses of the mammal class because they share some common features:


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial