O'Reilly logo

Object-Oriented Programming with Visual Basic .NET by J.P. Hamilton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 4. Object-Orientation

Several different mechanisms of reuse are available in Visual Basic. Implementation inheritance allows you to derive a child class from a parent class. The behaviors of the parent class are inherited by the child and possibly extended. The parent class typically contains general operations (if any), while the child class contains more specialized behaviors. The relationship is known as an is-a relationship (i.e., a Car is a Vehicle).

The second type of reuse, which is often confusing to beginning programmers, is containment. In containment, one class contains another, representing a has-a relationship. For instance, a Vehicle has a Motor.

Finally, in Chapter 5, you will learn about interface-based programming. Interfaces represent services that don't necessarily conform to class boundaries. The relationship could be described as a provides-a relationship. A Vehicle, for example, can be painted, but so can a House. These two objects are completely different, unrelated in almost every way. Although painting either object would involve vastly different work, a common description of the process (characterized by a common verb, such as "to paint") is possible.

While the syntax of each type of reuse is simple, the when and the why require more of an explanation. For instance, not all relationships defined in terms of is-a are appropriate for inheritance. Improper modeling of these relationships accounts for many of the design errors in an object-oriented ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required