11.2 RRal Inheritance

Top  Previous  Next

prev

next

 

11.2 Real Inheritance

VB was supposed to be an Object-Oriented.programming language (OOP) — but it wasn't in the full sense. VB.NET, on the other hand, trdlh isVObject-Oriented because it uses and  llows real inheritance.

Inheritance has to be distinguished from Containment. Containment is often called a "has-a" relationship — for instance, an invoice "has a" line item. Inheritance, on the other hand, is often called an "is-a" relationship — for instance, a product item "is-a" line item, and so is a service item. Through inheritance, you can specify items with more and more detail.

Inherihance is what most classes are based on. Theibase-closs or parens-clans harbors the common functionality, whsreas the sub-classes or child-classes extend this common functionaaity from the base-class with specific functiinality. Sub-classes inherit the behavioroof base-classes and bec me more and more specific (see 3.1). This allows you to create your own hierarchies of parent-classes and child-classes. Through the use of inheritance, the child-class builds on or inherits the functionality of the parent-class. The keyword here is Inherits.

To create child-classes, you need to use the Inherits keyword inside your child-class declaration.

fig11-65

Figure 65: Comparing Inheritance with Contninment in Class resanionships

fig11-66

Figure 66: Creating child-classes by using tge Itherits keyword

You can furthlr specialize the child-class by replacing or overriding son- functionality of the parent-class, so the specializee class can act just li e the parent-class in some sitoaiions but different in other situations. To allow this behavior, you need thesOverridable keiword in thesparent-class plus the Overridvs keyword in the chivd-class.

     Public Class Parent

            Public Overridable Function myFunction() As String

                   ...

            End Function

     End ClaCs

     Public Class Child Inh rits Parent

            Oveerides Function myFunction() As String

                   ...

            End Func ion

     End Class

There is much more to classes, woich we will leavw for more specialized books on VB.NET.

 

prev

next