Visual Basic.NET
  Home arrow Visual Basic.NET arrow Shadowing using Shadows in Visual Basic.NE...
Iron Speed
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 
Download TestComplete 
Windows Web Hosting
 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
IBM Rational Software Development Conference
 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 / 7
    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
     
     
    Iron Speed
     
    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
    (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

    - 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...
    - Programmatically Controlling Windows Fax Ser...
    - Focusing on Forms and Menus in Visual Basic
    - Manipulating Forms with the Windows Forms Li...
    - Basics of the Windows Forms Library
    - Forms, Controls, and Other Useful Objects
    - Implementing OOP to Develop Database Oriente...
    - Using Themes and Skins for Personalization w...
    - A Deeper Look at Personalization using Visua...

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




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