Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 6 - 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 
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: 5 stars5 stars5 stars5 stars5 stars / 9
    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

    Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

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


    (Page 6 of 6 )

    In the previous section, we observed that the keyword "shadows" completely hides based on name and not on signature.  But what if we want to access all the methods from the parent through the child (without shadowing)?  It is possible with "overloads!"

    Let us redefine our classes as follows:

    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 Child2

      Inherits Parent

     

      Public Overloads Sub DispMsg()

        MessageBox.Show("From child2")

      End Sub

     

    End Class

    If you observe the "Child2," class, I replaced "shadows" with "overloads."  This hides based on signature and not on name.

    Let us test the classes using the following statements:

        Dim objParent As New Parent

        objParent.DispMsg()

        objParent.DispMsg("Custom msg for parent")

    We should not have any problem with the above, and indeed, it works successfully. Now let us proceed with the child object as follows:

        Dim objChild As New Child2

        Dim RefParent As Parent = objChild

        objChild.DispMsg()

        objChild.DispMsg("Custom msg for child2") 'works with overload

        RefParent.DispMsg()

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

    Now you can see that we are able to access all of the methods in the child and also in the parent (using a parent reference).

    My previous article gave a good in depth understanding of "overrides" and "overloads" in Visual Basic 2005.  This article completely discussed "shadows" together with "overloads" in Visual Basic 2005.  In my next article, you will find information on "abstract" classes and "interfaces" together defining "polymorphism" using Visual Basic 2005. 

    I hope you enjoyed the article and any suggestions, bugs, errors, enhancements etc. are highly appreciated at http://jagchat.spaces.live.com


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

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

    VISUAL BASIC.NET ARTICLES

    - 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...
    - More on Controlling Windows Fax Services Usi...





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