Visual Basic.NET
  Home arrow Visual Basic.NET arrow 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


    (Page 1 of 6 )

    This article gives you an in-depth understanding of how to use "Shadows" in Visual Basic 2005. You will also see how "overloads" can replace "shadows" in certain situations.
    A downloadable zip file is available for this article.

    If you are new to OOP in Visual Basic.NET, I strongly suggest you to go through the following links:

    Constructors with Object-Oriented Database Development

    Properties and Object-Oriented Database Development

    Methods with Object-Oriented Database Development

    Introduction to Object-Oriented Database Development

    The entire source code for this article is available in the form of a downloadable zip file.  The solution was developed using Microsoft Visual Studio 2005 Professional Edition on Microsoft Windows Server 2003 Enterprise Edition.  I didn't really test it in any other environment.  I request that you post in the discussion area if you have any problems in execution.

    A simple demonstration of "Shadows" in Visual Basic 2005

    In my previous article, I discussed overloading and overriding in Visual Basic 2005.  Now, I shall discuss Shadowing in Visual Basic 2005.  Before going into the explanation, let us go through the following sample:

    Public Class Parent

      Public x As Integer = 10

    End Class

     

    Public Class Child

      Inherits Parent

      Public x As Integer = 20

    End Class

    I defined two classes, "Parent" and "Child," where "Child" gets inherited from "Parent."  If I create an object (instance) with respect to "Parent" and access the field (x) as follows, there is no doubt that it displays "10."

    Dim obj As New Parent

    MessageBox.Show(obj.x)

    However, if I create an object with respect to "Child" and access the field (x) as follows, the confusion starts:

    Dim obj As New Child

    MessageBox.Show(obj.x)

    The class "Child" is equipped with the same field (x) twice -- one inherited from "Parent" and one of its own.  If such a situation occurs, the field in the "child" shadows the field in "parent."  In other words, the child member temporarily hides the parent member and activates its own. This is called shadowing.

    Even though we don't specify the word "shadows," the editor gives a warning message and defaults to "Shadows."  The rewritten field for the above is as follows:

      Public Shadows x As Integer = 20 'default is shadows even if it is not defined

    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 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek