The Basic Mechanics of Inheritance
Recall from the previous chapter that inheritance is the aspect of OOP that facilitates code reuse.
Specifically speaking, code reuse comes in two flavors: classical inheritance (the “is-a” relationship)
and the containment/delegation model (the “has-a” relationship). Let’s begin this chapter by exam-
ining the classical “is-a” inheritance model.
When you establish “is-a” relationships between classes, you are building a dependency
between two or more class types. The basic idea behind classical inheritance is that new classes
may leverage (and possibly extend) the functionality of existing classes. To begin with a very simple
example, create a new Console Application project named BasicInheritance. Now assume you have
designed a simple class named Car that models some basic details of an automobile:
Do'stlaringiz bilan baham: |