Object-Oriented Programming with Objective-C by Apple Inc

Object-Oriented Programming with Objective-C by Apple Inc

Author:Apple Inc.
Language: eng
Format: epub
Publisher: www.apple.com


Inheritance

The easiest way to explain something new is to start with something understood. If you want to describe what a schooner is, it helps if your listeners already know what a sailboat is. If you want to explain how a harpsichord works, it’s best if you can assume your audience has already looked inside a piano, or has seen a guitar played, or at least is familiar with the idea of a musical instrument.

The same is true if you want to define a new kind of object; the description is simpler if it can start from the definition of an existing object.

With this in mind, object-oriented programming languages permit you to base a new class definition on a class already defined. The base class is called a superclass; the new class is its subclass. The subclass definition specifies only how it differs from the superclass; everything else is taken to be the same.

Nothing is copied from superclass to subclass. Instead, the two classes are connected so that the subclass inherits all the methods and instance variables of its superclass, much as you want your listener’s understanding of schooner to inherit what they already know about sailboats. If the subclass definition were empty (if it didn’t define any instance variables or methods of its own), the two classes would be identical (except for their names) and would share the same definition. It would be like explaining what a fiddle is by saying that it’s exactly the same as a violin. However, the reason for declaring a subclass isn’t to generate synonyms; it to create something at least a little different from its superclass. For example, you might extend the behavior of the fiddle to allow it to play bluegrass in addition to classical music.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.