Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 5 - 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  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
Moblin 
JMSL Numerical Library 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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: 4 stars4 stars4 stars4 stars4 stars / 10
    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

    Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!

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


    (Page 5 of 6 )

    This is a different situation when compared to any of the previous sections. I would like to have overloaded methods in the parent and "shadow" a method in the child.

    Let us go through the following code first:

    Public Class Parent

     

      Public Sub DispMsg()

        MessageBox.Show("From Parent")

      End Sub

     

      Public Sub DispMsg(ByVal Msg As String)

        MessageBox.Show(Msg)

      End Sub

     

    End Class

     

    Public Class Child

      Inherits Parent

     

      Public Shadows Sub DispMsg()

        MessageBox.Show("From child")

      End Sub

     

    End Class

    In the "Parent" class I defined two overloaded methods named "DispMsg" (one with a parameter and the other without a parameter).  In the "Child" class I am shadowing only the method that does not have a parameter.

    Let us try to access the members with the following testing statements:

        Dim objParent As New Parent

        objParent.DispMsg()

        objParent.DispMsg("Custom msg for parent")

    No problem, the above works as the parent has both methods.  Let us proceed to the following:

        Dim objChild As New Child

        Dim RefParent As Parent = objChild

        objChild.DispMsg()

        'objChild.DispMsg("Custom msg for child") 'wont work with shadow

        RefParent.DispMsg()

        RefParent.DispMsg("Custom msg from ref object")

    From the above, you can understand that we can still access both parent methods from a parent reference.  But the child can access only the shadowed method.  In other words, the keyword "shadows" completely hides based on name and not on signature.

    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

    - Entity Creation and Messaging in a VB.NET Te...
    - Movement and Player Statistics in a VB.NET T...
    - Creating and Drawing a Game Map in VB.NET
    - Working with Classes and Properties for Game...
    - Working with Loops, Arrays, and Collections ...
    - Learning Loops in VB.NET for Game Development
    - Learning VB.NET: Working with Variables, Con...
    - The Basics of VB.NET Through Text Game Devel...
    - Learning VB.NET Through Text Game Development
    - Types of Operators in Visual Basic
    - Operators
    - Understanding Custom Events using Visual Bas...
    - Polymorphism using Abstract Classes in Visua...
    - Shadowing using Shadows in Visual Basic.NET ...
    - Overloading and Overriding in Visual Basic.N...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway