VB'NET Inheritance and Interfaces - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

VB'NET Inheritance and Interfaces

Description:

... based on an existing class, inheriting its interface and functionality from the base class. ... is a class that inherits methods, properties, attributes and ... – PowerPoint PPT presentation

Number of Views:565
Avg rating:3.0/5.0
Slides: 15
Provided by: richardv9
Category:

less

Transcript and Presenter's Notes

Title: VB'NET Inheritance and Interfaces


1
VB.NET Inheritance and Interfaces
  • Richard Vantrease

2
Introduction
  • Inheritance a class can based on an existing
    class, inheriting its interface and functionality
    from the base class.
  • Interface the public methods, properties,
    events and fields

3
Diagramming Inheritance
Diagram created with Poseidon for UML Community
Edition
4
Base and Sub Classes
  • A base class is a class that another class
    inherits its methods, properties, attributes and
    events from.
  • A sub class is a class that inherits methods,
    properties, attributes and events from.

5
Multi-Level Inheritance
  • Inheritance is able to go multiple levels.
  • Sometimes referred to as an inheritance chain.
  • Person
  • Employee
  • Exempt
  • Non-Exempt
  • Customer

6
Reference Keywords
  • Me current object instance
  • MyBase Immediate parent or base class. There
    is no built in way to navigate beyond immediate
    parent class.
  • MyClass Object reference to current class.

7
Overload
  • Different method signature, different
    functionality.
  • Base Class
  • Sub Class
  • Uses overloads keyword
  • Public Overloads Property FName

8
Override
  • Same method signature, different functionality.
  • Base Class
  • Uses overridable keyword
  • Public Overridable Property FName
  • Sub Class
  • Uses overrides keyword
  • Public Overrides Property FName

9
Virtual Methods Reference
10
Shadow
  • Allows methods in the base class that were not
    declared as overridable to be replaced in the sub
    class.

11
Abstract Base Class
  • A class that can only act as a base class.
  • Provides no implementation, only interface
    definitions.
  • Class uses the MustInherit keyword.
  • Public MustInherit Class Person
  • Method uses the MustOverride keyword
  • Public MustOverride Sub Method1()

12
Interfaces
  • Default Interface
  • Secondary Interfaces
  • Implementation Re-Use

13
Default Interface
  • Used when class is used as the type in both the
    declaration and instantiation statements.
  • Dim MyObject as Class1
  • MyObject New Class1

14
Secondary Interface
  • Interface is created much like a class.
  • Public Interface ISecInterface
  • ReadOnly Property Count () As Integer
  • Sub DoSomething ()
  • End Interface
  • Implemented with the implements keyword.
  • Subs and Properties must use the implements
    keyword (i.e. Implements ISecInterface.Count)
Write a Comment
User Comments (0)
About PowerShow.com