The Role of Inheritance
The next pillar of OOP, inheritance, boils down to the language’s ability to allow you to build new
class definitions based on existing class definitions. In essence, inheritance allows you to extend the
behavior of a base (or parent) class by inheriting core functionality into the derived subclass (also
called a
child class). Figure 5-8 shows a simple example.
You can read the diagram in Figure 5-8 as “A Hexagon is-a Shape that is-an Object.” When you
have classes related by this form of inheritance, you establish “is-a” relationships between types.
The “is-a” relationship is termed classical inheritance.
Here, you can assume that Shape defines some number of members that are common to all
descendents. Given that the Hexagon class extends Shape, it inherits the core functionality defined by
Shape and Object, as well as defines additional hexagon-related details of its own (whatever those
may be).
Do'stlaringiz bilan baham: |