Page 12 - Open Soource Technologies 304.indd
P. 12
Unit 1: Introduction to Visual Basic
object as if it were a black box, which leads to increased maintainability. Along the same lines, Notes
polymorphism allows you to write less code because each individual object does not have to be
dealt with separately. Finally, polymorphism lends itself to writing code that can be reused
because it will not be specific to a particular object.
1.2.3 Inheritance
The final OO concept is inheritance. Inheritance allows objects to share their interfaces (the
definition of their members) and/or implementation in a hierarchy. For example, Tyrannosaurus
and Velociraptor objects might be derived or inherited from a more generic Theropod object.
All three objects share a basic set of members and, possibly, behaviors, such as carnivorousness,
although the descendant objects might also include additional members or override members
of Theropod. Inheritance allows objects to become more specific further down the hierarchy by
adding additional members. In a nutshell, inheritance allows objects to reuse features (either
their definition or their code) of other objects to which they are naturally related. The primary
benefit of inheritance is, thus, reuse.
Obviously, inheritance and polymorphism are closely related, and, in fact, inheritance is what
makes polymorphism possible in OO designs. It is always the case that objects that are in an
inheritance relationship can be treated polymorphically. For example, if the Velociraptor object
is inherited from the Theropod object, any consumer that is designed to work with Theropod
objects will also work with Velociraptor objects.
VB.NET developers can benefit from inheritance in two ways: through interface inheritance and
implementation inheritance. Interface inheritance allows only the definition of the object to be
reused, whereas implementation inheritance allows the actual code written for the ancestor
object (and its ancestors all the way down the line) to be reused.
Note If developers wanted to use a form of implementation inheritance in previous
versions of VB, they had to design classes to take advantage of the concepts of containment
and delegation. Basically, these concepts mean that a class accessible by a consumer will
contain a private instance of a second class and delegate its services to the consumer
through its own interface. Containment and delegation are familiar terms (along with
aggregation) to COM programmers.
Self Assessment
Fill in the blanks:
3. ........................ means that an object can hide its internal data structures from consumers of
the object.
4. ........................ allows you to write code that is generic across a set of objects that provide
the same public members.
5. ........................ allows objects to share their interfaces (the definition of their members)
and/or implementation in a hierarchy.
1.3 Visual Basic .NET
Visual Basic .NET is an Object-oriented programming language designed by Microsoft. With the
word “Basic” being in the name of the language, you can already see that this is a language for
LOVELY PROFESSIONAL UNIVERSITY 5