Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 4 - Shadowing using Shadows in Visual Basic.NE...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
VISUAL BASIC.NET

Shadowing using Shadows in Visual Basic.NET 2005
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 15
    2007-07-31

    Table of Contents:
  • Shadowing using Shadows in Visual Basic.NET 2005
  • Accessing parent members when using Shadows in Visual Basic 2005
  • Using Shadows with properties in Visual Basic 2005
  • Using Shadows with methods in Visual Basic 2005
  • Using Shadows with overloaded parent methods in Visual Basic 2005
  • Using Overloads instead of Shadows with overloaded parent methods in Visual Basic 2005

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Shadowing using Shadows in Visual Basic.NET 2005 - Using Shadows with methods in Visual Basic 2005


    (Page 4 of 6 )

    In previous sections, I discussed both fields and properties using "shadows."  "Shadows" are not limited to "Fields" and "Properties;" they can also be used for "methods."  Now I'm extending  the discussion to "methods."

    Consider the following code before we proceed:

    Public Class Parent

     

      Public Sub DispMsg()

        MessageBox.Show("From Parent")

      End Sub

     

    End Class

     

    Public Class Child

      Inherits Parent

     

      Public Shadows Sub DispMsg()

        MessageBox.Show("From child")

      End Sub

     

    End Class

    In the above two classes, there exists the same method, "DispMsg," with the same signature (which may have different implementations). Thus we need "shadows."

    We can test the above classes using the following style of code:

        Dim objParent As New Parent

        Dim objChild As New Child

     

        objParent.DispMsg()

        objChild.DispMsg()

    And finally, using a parent reference, we can test as follows (which displays "From Parent"):

        Dim RefParent As Parent = objChild

        RefParent.DispMsg()

    We can even access a parent member without creating a separate reference variable as follows:

        CType(objChild, Parent).DispMsg()

    The above applies even to shadowed "fields" and "properties."

    More Visual Basic.NET Articles
    More By Jagadish Chaterjee


       · Hello guys,Not every traditional OOP developers know about "Shadows" in Visual...
     

    VISUAL BASIC.NET ARTICLES

    - User-defined Functions using Visual Basic Ap...
    - Understanding Object Binding in VBA
    - Mastering the Message Box
    - Testing a Windows Forms Application
    - Using Visual Basic.NET Features to Code a Wi...
    - Correcting Code in a Windows Forms Applicati...
    - Write Readable Code and Comments for Windows...
    - How to Code and Test a Windows Forms Applica...
    - Adding Features to a Windows Forms Applicati...
    - How to Design a Windows Forms Application
    - LINQ to XML Programming Using Visual Basic.N...
    - Understanding Delegates using Visual Basic.N...
    - Create a Sudoku Puzzle Generator using VB.NET
    - Entity Creation and Messaging in a VB.NET Te...
    - Movement and Player Statistics in a VB.NET T...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek