473,570 Members | 2,937 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help on Shadows

Hi Friends
I am little confused about the shadows keyword in VB.NET
could anyone explain with an example about Shadows keyword

Many thanks
Satish

Nov 20 '05 #1
7 7125
* "Satish" <kv********@hot mail.com> scripsit:
I am little confused about the shadows keyword in VB.NET
could anyone explain with an example about Shadows keyword


Your system date/time is wrong.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #2
On Sat, 18 Oct 2003 00:01:11 +0530, "Satish" <kv********@hot mail.com>
wrote:
Hi Friends
I am little confused about the shadows keyword in VB.NET
could anyone explain with an example about Shadows keyword


The "Shadows" keyword is used for a special kind of overloading. In
its broadest terms, it is used to overload functions and offer a
different return type (for example). This is particularly useful when
implementing strongly-typed objects.

Here is an example of a strongly typed ArrayList (for "ITestClass "
objects):
--begin example--

Public Class TestClassArrayL ist
Inherits System.Collecti ons.ArrayList
Implements ITestClassColle ction

Public Sub New()
MyBase.New
End Sub

Public Shadows Function Add(ByVal Value As ITestClass) As
Integer Implements ITestClassColle ction.Add
Return MyBase.Add(Valu e)
End Function

Public Shadows Function Remove(ByVal Value As ITestClass)
Implements ITestClassColle ction.Remove
MyBase.Remove(V alue)
End Function

Default Shadows Public Property Item(ByVal index As Integer)
As ITestClass Implements ITestClassColle ction.Item
Get
Return MyBase.Item(ind ex)
End Get
Set(ByVal Value As ITestClass)
MyBase.Item(ind ex) = Value
End Set
End Property

Public Shadows Function BinarySearch(By Val Index As Integer,
ByVal Count As Integer, ByVal Value As ITestClass, ByVal Comparer As
IComparer) As Integer
Return MyBase.BinarySe arch(Index, Count, Value,
Comparer)
End Function

Public Shadows Function BinarySearch(By Val Value As
ITestClass) As Integer
Return MyBase.BinarySe arch(Value)
End Function

Public Shadows Function BinarySearch(By Val Value As
ITestClass, ByVal Comparer As IComparer) As Integer
Return MyBase.BinarySe arch(Value, Comparer)
End Function

Public Shadows Function Contains(ByVal item As ITestClass) As
Boolean Implements ITestClassColle ction.Contains
Return MyBase.Contains (item)
End Function

Public Shadows Function IndexOf(ByVal Value As ITestClass) As
Integer Implements ITestClassColle ction.IndexOf
Return MyBase.IndexOf( Value)
End Function

Public Shadows Function IndexOf(ByVal Value As ITestClass,
ByVal startIndex As Integer) As Integer
Return MyBase.IndexOf( Value, startIndex)
End Function

Public Shadows Function IndexOf(ByVal Value As ITestClass,
ByVal startIndex As Integer, ByVal count As Integer) As Integer
Return MyBase.IndexOf( Value, startIndex, count)
End Function

Public Shadows Function LastIndexOf(ByV al Value As ITestClass)
As Integer
Return MyBase.LastInde xOf(Value)
End Function

Public Shadows Function LastIndexOf(ByV al Value As ITestClass,
ByVal startIndex As Integer) As Integer
Return MyBase.LastInde xOf(Value, startIndex)
End Function

Public Shadows Function LastIndexOf(ByV al Value As ITestClass,
ByVal startIndex As Integer, ByVal count As Integer) As Integer
Return MyBase.LastInde xOf(Value, startIndex, count)
End Function

Public Shadows Sub Insert(ByVal index As Integer, ByVal value
As ITestClass)
MyBase.Insert(i ndex, value)
End Sub

End Class

--end example--

Here's a closer look at the Add(Value) method. The base class
(ArrayList) has the method:

Add(Value As Object)

But in a strongly-typed system, our collection is a "collection of
ITestClass objects" and NOT a "collection of Objects". So, we don't
want to expose the base class's Add method - we want the parameter to
force an ITestClass object instead. The Shadows keyword has the effect
of replacing the base class method with the new one.

The TestClassArrayL ist therefore can only hold ITestClass objects. We
still have access to the non-type specific functions/properties such
as Count() through the inheritance.

The same can be done with Collection, HybridDictionar y, ListBox etc.
and is my preferred modelling approach. You might think this is a lot
of work to achieve little, but I've written a code-generator to
produce all of these things for me. In fact, it generates a complete
DAL for SQL Server databases, as it incorporates a complete template
parser. If anyone would like to beta-test it, I'd very much appreciate
it!

Rgds,

Nov 20 '05 #3
"Satish" <kv********@hot mail.com> schrieb
Hi Friends
I am little confused about the shadows keyword in VB.NET
could anyone explain with an example about Shadows keyword

Have you already read the following topic?

<F1>
VS.Net
VB and VC#
Reference
Visual Basic language
Tour through VB
Feature
Declared elements
Declared element reference
Shadowing

Direct link:

http://msdn.microsoft.com/library/en...nShadowing.asp

--
Armin

Nov 20 '05 #4
thanks Mr.Andy for you detailed explanation.

i have a doubt.
Shadows is not just used for method overloading, we can shadow a simple
variable of base class with the method(really a method not variable) of
derived class, for that matter any type can be shadowed by any other type.
only thing is that names should be same. This is the point where i really
got confused. Is there any similar mechanism in other OO languages

The following paragraph i am picking from .NET SDK

The Shadows keyword indicates that a declared programming element shadows,
or hides, an identically named element, or set of overloaded elements, in a
base class. You can shadow any kind of declared element with any other kind

Can you give your further explanation on this,
Many thanks
Nov 20 '05 #5
On Sun, 19 Oct 2003 08:29:24 +0530, "Satish" <ne******@hotma il.com>
wrote:
thanks Mr.Andy for you detailed explanation.

i have a doubt.
Shadows is not just used for method overloading, we can shadow a simple
variable of base class with the method(really a method not variable) of
derived class, for that matter any type can be shadowed by any other type.
only thing is that names should be same.
True. But such horridness you should really whisper.

If you start changing properties into functions, functions into
subroutines, objects into methods (etc) you will encounter problems
when using those objects from outside of the project. Although
possible, it is such an extraordinarily bad practice that I would
murder anyone who implemented such a messy construct. It is there for
completeness and the only time I ever allow the use of it is when
implementing unit-test objects. But even then...

--begin horrid example--

Public Class TestBase
Protected Collection As New ArrayList()

Public Sub WriteType()
Debug.WriteLine (Collection.Get Type)
End Sub
End Class

Public Class Test
Inherits TestBase

Public Shadows Function Collection() As
Specialized.Str ingDictionary
Return New Specialized.Str ingDictionary()
End Function

Public Sub WriteLocalType( )
Debug.WriteLine (Collection.Get Type)
End Sub
End Class
--end horrid example--
This is the point where i really
got confused. Is there any similar mechanism in other OO languages
No, not in C++ or Java, as far as I remember. When used properly, it
is extremely useful.
The following paragraph i am picking from .NET SDK

The Shadows keyword indicates that a declared programming element shadows,
or hides, an identically named element, or set of overloaded elements, in a
base class. You can shadow any kind of declared element with any other kind

Can you give your further explanation on this,


Exactly as we've said: You can shadow any property, member, function
or subroutine with anything else. The name of the element is the same,
but the type (inc. parameter declarator) will differ.

Nov 20 '05 #6
Thanks again Mr.Andy,
you made very clear with your detailed explanation.
with your example i would able to get a new dimension in my work.
Thanks a lot,hope your extend your support future...
Satish
"_Andy_" <wi******@nospa mthanks.gov> wrote in message
news:gr******** *************** *********@4ax.c om...
On Sun, 19 Oct 2003 08:29:24 +0530, "Satish" <ne******@hotma il.com>
wrote:
thanks Mr.Andy for you detailed explanation.

i have a doubt.
Shadows is not just used for method overloading, we can shadow a simple
variable of base class with the method(really a method not variable) of
derived class, for that matter any type can be shadowed by any other type.only thing is that names should be same.


True. But such horridness you should really whisper.

If you start changing properties into functions, functions into
subroutines, objects into methods (etc) you will encounter problems
when using those objects from outside of the project. Although
possible, it is such an extraordinarily bad practice that I would
murder anyone who implemented such a messy construct. It is there for
completeness and the only time I ever allow the use of it is when
implementing unit-test objects. But even then...

--begin horrid example--

Public Class TestBase
Protected Collection As New ArrayList()

Public Sub WriteType()
Debug.WriteLine (Collection.Get Type)
End Sub
End Class

Public Class Test
Inherits TestBase

Public Shadows Function Collection() As
Specialized.Str ingDictionary
Return New Specialized.Str ingDictionary()
End Function

Public Sub WriteLocalType( )
Debug.WriteLine (Collection.Get Type)
End Sub
End Class
--end horrid example--
This is the point where i really
got confused. Is there any similar mechanism in other OO languages


No, not in C++ or Java, as far as I remember. When used properly, it
is extremely useful.
The following paragraph i am picking from .NET SDK

The Shadows keyword indicates that a declared programming element shadows,or hides, an identically named element, or set of overloaded elements, in abase class. You can shadow any kind of declared element with any other kind
Can you give your further explanation on this,


Exactly as we've said: You can shadow any property, member, function
or subroutine with anything else. The name of the element is the same,
but the type (inc. parameter declarator) will differ.

Nov 20 '05 #7
Just wanted to confuse people further :)

the main idea behind the shadows keyword is not to allow you to hide
elements in your base class - it's to prevent against your class being
broken by someone adding a new element to your base class that ends up
having the same name as an element you your class (for example, if you
upgrade a library version, and it now has a new element that conflicts with
an element in you class - in this case we will shadow the base class's
element and your class should still work as you expect it.)

While some people may devise other uses for the feature, this was the
primary reason to have it - using it to cause other people/code to
reference one object rathen than another can lead to those people's code
having unexpected behavior, and is generally a bad idea.

--------------------
From: "Satish" <kv********@hot mail.com>
Subject: Help on Shadows
Date: Sat, 18 Oct 2003 00:01:11 +0530
Lines: 11
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
Message-ID: <Oe************ **@TK2MSFTNGP12 .phx.gbl>
Newsgroups: microsoft.publi c.dotnet.langua ges.vb
NNTP-Posting-Host: 202.63.102.117
Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP12.phx.g bl
Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.vb:148090
X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vb

Hi Friends
I am little confused about the shadows keyword in VB.NET
could anyone explain with an example about Shadows keyword

Many thanks
Satish



Nov 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2097
by: Christopher W. Douglas | last post by:
I am developing a VB.NET app using Visual Studio.NET 2003. VB.NET allows me to create a class with two or more methods that have the same name, as long as they have different (non-optional) arguments, such as: FirstClass Public Sub Populate(string) Public Sub Populate(string, string) I don't have to use Overloads, because both methods...
10
3207
by: Özden Irmak | last post by:
Hi, I'm trying to hide an event of my custom usercontrol derived control, something like "Shadows" in VB.Net, but although the event is hidden from PropertyGrid, from CodeEditor I can still see/reach it. I use this code :
8
13291
by: Dot net work | last post by:
I need VB.NET's "shadows" functionality inside a C# project. I tried the "new" keyword, but it didn't seem to work, because my particular function does in fact differ in signature to the function that is being hidden in the base class. In VB.NET, the shadows keyword hides all the inherited functions, regardless of signature. I need...
10
3019
by: Lino Barreca | last post by:
Take a look at this code: Class clsAnagrafica Public Overridable ReadOnly Property Codice() As Integer Get Return 1 End Get End Property End Class
12
1247
by: D Miller | last post by:
This may be a basic question, but it sure has me stumpted.. I have two classes, Class1 and Class2. Class 2 inherits class one. Each class has some varibles that need to be reset from time to time, so I have created a method call "Clear" that does that. So my question is when using "Clear" in an instance of class two, the clear method...
6
1483
by: Jeff Johnson [MVP: VB] | last post by:
I'm developing a form which is to be used as an enhanced MessageBox(). I don't want it to be shown with the default Show() method, so as I provided overloaded versions of Show() I marked them as Shadows and I didn't provide a parameterless version of Show(). Would it have been better (or would this have even worked) to simply make a Private...
0
1239
by: jmzl666 | last post by:
Hi all, i hope i can explain mysel, english is no my first language. Well, i have a base class (a wrapper to work with oledb) with some properties and methods, and i have a inherited class (wrapper to odbc), something like this: Public Class Base Protected Connection as OleDbConnection Protected Command as OleDbCommand Public ReadOnly...
1
1589
by: menyki | last post by:
please can somebody help me debug this code. i wrote a code that will display a form within an interval but the is generating alot of errors. the code is as shown below. (am using visual basic.Net). The timer code is coming from the splash and the form (mainForm) has already been designed. Dim myTimer As New System.Timers.Timer...
2
6548
by: =?Utf-8?B?QU1lcmNlcg==?= | last post by:
In the class below, I inherit from Generic.Dictionary so I can override property Item. Item is not overridable, so I used Shadows, and it works as I want. It works equally well if I replace Shadows with Overloads. Question 1 - Which is preferred in a case like this, Shadows or Overloads. Question 2 - The Override clan (Overrides,...
0
7726
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8150
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7700
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6329
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5523
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5247
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3682
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2131
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
971
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.