473,387 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 7112
* "Satish" <kv********@hotmail.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********@hotmail.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 TestClassArrayList
Inherits System.Collections.ArrayList
Implements ITestClassCollection

Public Sub New()
MyBase.New
End Sub

Public Shadows Function Add(ByVal Value As ITestClass) As
Integer Implements ITestClassCollection.Add
Return MyBase.Add(Value)
End Function

Public Shadows Function Remove(ByVal Value As ITestClass)
Implements ITestClassCollection.Remove
MyBase.Remove(Value)
End Function

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

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

Public Shadows Function BinarySearch(ByVal Value As
ITestClass) As Integer
Return MyBase.BinarySearch(Value)
End Function

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

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

Public Shadows Function IndexOf(ByVal Value As ITestClass) As
Integer Implements ITestClassCollection.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(ByVal Value As ITestClass)
As Integer
Return MyBase.LastIndexOf(Value)
End Function

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

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

Public Shadows Sub Insert(ByVal index As Integer, ByVal value
As ITestClass)
MyBase.Insert(index, 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 TestClassArrayList 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, HybridDictionary, 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********@hotmail.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******@hotmail.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.GetType)
End Sub
End Class

Public Class Test
Inherits TestBase

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

Public Sub WriteLocalType()
Debug.WriteLine(Collection.GetType)
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******@nospamthanks.gov> wrote in message
news:gr********************************@4ax.com...
On Sun, 19 Oct 2003 08:29:24 +0530, "Satish" <ne******@hotmail.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.GetType)
End Sub
End Class

Public Class Test
Inherits TestBase

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

Public Sub WriteLocalType()
Debug.WriteLine(Collection.GetType)
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********@hotmail.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.public.dotnet.languages.vb
NNTP-Posting-Host: 202.63.102.117
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:148090
X-Tomcat-NG: microsoft.public.dotnet.languages.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
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)...
10
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...
8
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...
10
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
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...
6
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...
0
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...
1
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)....
2
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.