O'Reilly logo

Visual Basic® .NET by Example by Bob Donald, Gabriel Oancea

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

Simple Inheritance

How does inheritance solve the issues you had with your Employee and Customer classes? Well, you can apply the generalization process and move from particular to general. In your example you noticed that three of the properties are common to both classes. That means that you could have a base class named Person, for example, in which you place the common properties. Then you inherit from this class both your Employee and Customer classes. In this way you solve both issues (code reuse and common behavior). Let's see how this is done. First you write the base class:

 Public Class Person Private m_name As String Private m_dob As Date Private m_email As String Public Property name() As String Get Return m_name End Get Set m_name ...

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