473,513 Members | 2,561 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question on "Shadowing"

I'm trying to derive a class from a typed DataSet to add some methods to one
of the DataTables. I would like to keep the names the same in the derived
class as in the base class, so I have used "Shadows" to hide the base class
members. However, this does not seem to work. Any pointers as to what I'm
doing wrong here? (I've attached the basics of the code below). Thanks

Dave Taylor

I have something similar to the following for the base class

Public Class dsConfig
Inherits DataSet

Private tableStreams As StreamsDataTable

Public Class StreamsDataTable
Inherits DataTable
....
End Class

Public ReadOnly Property Streams As StreamsDataTable
Get
Return tableStreams
End Get
End Property
...
End Class
For the derived class I have

Public Class dsConfigEx
Inherits dsConfig

Private Shadows tableStreams As dsConfigEx.StreamsDataTable

Public Shadows ReadOnly Property Streams As dsConfigEx.StreamsDataTable
Get
Return tableStreams
End Get
End Property

Public Shadows Class StreamsDataTable
Inherits dsConfig.StreamsDataTable

Public Function FindByPosition(ByVal Position As Integer) As
dsConfig.StreamsRow
...code to find & return row...
End Function
End Class
End Class


Nov 20 '05 #1
5 1657
NM
Hi,

A Private members in the base class aren't ihnerited in the derived class;
You should declare it as Protected;

I suggest that :

Public Class StreamsDataTable
Inherits DataTable
....
End Class

Public Class StreamsDataTableEx
Inherits StreamsDataTable

Public Function FindByPosition(ByVal Position As Integer) As
dsConfig.StreamsRow
...code to find & return row...
End Function
End Class

Public Class dsConfig
Inherits DataSet

Protected tableStreams As StreamsDataTable

Public ReadOnly Property Streams As StreamsDataTable
Get
Return tableStreams
End Get
End Property
...
End Class

Public Class dsConfigEx
Inherits dsConfig

End Class
Hope this help;
Regards.

----- Original Message -----
From: "Dave Taylor" <no**********@processeng.com>
Newsgroups: microsoft.public.dotnet.languages.vb
Sent: Tuesday, August 03, 2004 9:17 PM
Subject: Question on "Shadowing"

I'm trying to derive a class from a typed DataSet to add some methods to one of the DataTables. I would like to keep the names the same in the derived
class as in the base class, so I have used "Shadows" to hide the base class members. However, this does not seem to work. Any pointers as to what I'm doing wrong here? (I've attached the basics of the code below). Thanks

Dave Taylor

I have something similar to the following for the base class

Public Class dsConfig
Inherits DataSet

Private tableStreams As StreamsDataTable

Public Class StreamsDataTable
Inherits DataTable
....
End Class

Public ReadOnly Property Streams As StreamsDataTable
Get
Return tableStreams
End Get
End Property
...
End Class
For the derived class I have

Public Class dsConfigEx
Inherits dsConfig

Private Shadows tableStreams As dsConfigEx.StreamsDataTable

Public Shadows ReadOnly Property Streams As dsConfigEx.StreamsDataTable Get
Return tableStreams
End Get
End Property

Public Shadows Class StreamsDataTable
Inherits dsConfig.StreamsDataTable

Public Function FindByPosition(ByVal Position As Integer) As
dsConfig.StreamsRow
...code to find & return row...
End Function
End Class
End Class

Nov 20 '05 #2
"Dave Taylor" <no**********@processeng.com> wrote in message
news:e0**************@TK2MSFTNGP10.phx.gbl...
I would like to keep the names the same in the derived class as in
the base class, so I have used "Shadows" to hide the base class
members. However, this does not seem to work.


Bear in mind that, even if you Shadow a method, somebody (often
Visual Studio itself) can get around your defences by referencing the
base class method directly, as in

Class Base1
Public Sub Add( ...
. . .

Class Derived2
Inherits Base1
Public Shadows Sub Add( ...
. . .

then

Dim obj3 as New Derived2
Console.Writeline( obj3.Add( ... ' Calls Derived2.Add()

Dim obj4 as Base1 = obj3
Console.Writeline( obj4.Add( ... ' Calls Base1.Add()

(OK, so Shadows may not strictly hold for Subs, but the principle's
the thing I'm getting at).

HTH,
Phill W.
Nov 20 '05 #3
Thanks for the reply, however changing the base class' tableStreams member
from private to protected requires modifying the base class...something I'm
trying to avoid since the base class is generated from the DataSet designer.
I know I could use a new name, for example StreamsEx, but that's what I was
hoping to avoid with the "Shadows" statement.

Thanks again,
Dave Taylor

"NM" <NM****@hotmail.com> wrote in message
news:OT**************@TK2MSFTNGP09.phx.gbl...
Hi,

A Private members in the base class aren't ihnerited in the derived class;
You should declare it as Protected;

I suggest that :

Public Class StreamsDataTable
Inherits DataTable
....
End Class

Public Class StreamsDataTableEx
Inherits StreamsDataTable

Public Function FindByPosition(ByVal Position As Integer) As
dsConfig.StreamsRow
...code to find & return row...
End Function
End Class

Public Class dsConfig
Inherits DataSet

Protected tableStreams As StreamsDataTable

Public ReadOnly Property Streams As StreamsDataTable
Get
Return tableStreams
End Get
End Property
...
End Class

Public Class dsConfigEx
Inherits dsConfig

End Class
Hope this help;
Regards.

----- Original Message -----
From: "Dave Taylor" <no**********@processeng.com>
Newsgroups: microsoft.public.dotnet.languages.vb
Sent: Tuesday, August 03, 2004 9:17 PM
Subject: Question on "Shadowing"

I'm trying to derive a class from a typed DataSet to add some methods to

one
of the DataTables. I would like to keep the names the same in the derived class as in the base class, so I have used "Shadows" to hide the base

class
members. However, this does not seem to work. Any pointers as to what

I'm
doing wrong here? (I've attached the basics of the code below). Thanks

Dave Taylor

I have something similar to the following for the base class

Public Class dsConfig
Inherits DataSet

Private tableStreams As StreamsDataTable

Public Class StreamsDataTable
Inherits DataTable
....
End Class

Public ReadOnly Property Streams As StreamsDataTable
Get
Return tableStreams
End Get
End Property
...
End Class
For the derived class I have

Public Class dsConfigEx
Inherits dsConfig

Private Shadows tableStreams As dsConfigEx.StreamsDataTable

Public Shadows ReadOnly Property Streams As

dsConfigEx.StreamsDataTable
Get
Return tableStreams
End Get
End Property

Public Shadows Class StreamsDataTable
Inherits dsConfig.StreamsDataTable

Public Function FindByPosition(ByVal Position As Integer) As
dsConfig.StreamsRow
...code to find & return row...
End Function
End Class
End Class


Nov 20 '05 #4
If I were you, I would just drop the DataSet and write your own data classes
from scratch. That way everything will work the way you want it to.

Another option is to create a wrapper class. It doesn't really inherit from
the dataset, it merely exposes its members.

As for Shadows, it isn't really meant to be used except in extreme
circumstances. e.g. If a class you are inheriting has changed and you don't
want your code to break. You should just use a different name.

--
Jonathan Allen
"Dave Taylor" <no**********@processeng.com> wrote in message
news:e0**************@TK2MSFTNGP10.phx.gbl...
I'm trying to derive a class from a typed DataSet to add some methods to one of the DataTables. I would like to keep the names the same in the derived
class as in the base class, so I have used "Shadows" to hide the base class members. However, this does not seem to work. Any pointers as to what I'm doing wrong here? (I've attached the basics of the code below). Thanks

Dave Taylor

I have something similar to the following for the base class

Public Class dsConfig
Inherits DataSet

Private tableStreams As StreamsDataTable

Public Class StreamsDataTable
Inherits DataTable
....
End Class

Public ReadOnly Property Streams As StreamsDataTable
Get
Return tableStreams
End Get
End Property
...
End Class
For the derived class I have

Public Class dsConfigEx
Inherits dsConfig

Private Shadows tableStreams As dsConfigEx.StreamsDataTable

Public Shadows ReadOnly Property Streams As dsConfigEx.StreamsDataTable Get
Return tableStreams
End Get
End Property

Public Shadows Class StreamsDataTable
Inherits dsConfig.StreamsDataTable

Public Function FindByPosition(ByVal Position As Integer) As
dsConfig.StreamsRow
...code to find & return row...
End Function
End Class
End Class

Nov 20 '05 #5
So what is it that doesn't work as you expect?
As people have previously said, remember that code that deals with your class through a variable of the base class's type will still see the base type's
objects - the shadowing members are duplicates created in the derived class (they don't cause the ones in the base class to cease existing).

Alex
MS VB QA

--------------------
From: "Dave Taylor" <no**********@processeng.com>
Subject: Question on "Shadowing"
Date: Tue, 3 Aug 2004 13:17:16 -0600
Lines: 57
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
Message-ID: <e0**************@TK2MSFTNGP10.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: proxy.processeng.com 209.180.91.75
Path: cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFT NGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.languages.vb:221404
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

I'm trying to derive a class from a typed DataSet to add some methods to one
of the DataTables. I would like to keep the names the same in the derived
class as in the base class, so I have used "Shadows" to hide the base class
members. However, this does not seem to work. Any pointers as to what I'm
doing wrong here? (I've attached the basics of the code below). Thanks

Dave Taylor

I have something similar to the following for the base class

Public Class dsConfig
Inherits DataSet

Private tableStreams As StreamsDataTable

Public Class StreamsDataTable
Inherits DataTable
....
End Class

Public ReadOnly Property Streams As StreamsDataTable
Get
Return tableStreams
End Get
End Property
...
End Class
For the derived class I have

Public Class dsConfigEx
Inherits dsConfig

Private Shadows tableStreams As dsConfigEx.StreamsDataTable

Public Shadows ReadOnly Property Streams As dsConfigEx.StreamsDataTable
Get
Return tableStreams
End Get
End Property

Public Shadows Class StreamsDataTable
Inherits dsConfig.StreamsDataTable

Public Function FindByPosition(ByVal Position As Integer) As
dsConfig.StreamsRow
...code to find & return row...
End Function
End Class
End Class


Nov 21 '05 #6

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

Similar topics

14
24061
by: tertius | last post by:
Is there a better way to append certain chars in a string with a backslash that the example below? chr = "#$%^&_{}" # special chars to look out for str = "123 45^ & 00 0_" # string to...
17
1905
by: Istvan Albert | last post by:
Paul McGuire wrote: > Please reconsider the "def f() :" construct. Instead of > invoking a special punctuation character, it uses context and placement, > with familiar old 's, to infuse the...
5
2818
by: BJörn Lindqvist | last post by:
I think it would be cool if you could refer to instance variables without prefixing with "self." I know noone else thinks like me so Python will never be changed, but maybe you can already do it...
134
7750
by: James A. Donald | last post by:
I am contemplating getting into Python, which is used by engineers I admire - google and Bram Cohen, but was horrified to read "no variable or argument declarations are necessary." Surely that...
9
1787
by: Larry Woods | last post by:
I have a method in my base class that I want ALL derived classes to use. But, I find that I can create a "Shadow" method in my derived class that "overrides" the method in my base class. Can't...
0
1168
by: Klaus Löffelmann | last post by:
Hi, maybe it's already too late, but what is the deal with overwriting Object.Equals. I have to use "overrides overloads" to really overwrite the correct 'version' of equals, even if a single...
41
4241
by: JohnR | last post by:
In it's simplest form, assume that I have created a usercontrol, WSToolBarButton that contains a button. I would like to eventually create copies of WSToolBarButton dynamically at run time based...
39
3141
by: utab | last post by:
Dear all, Is there a clear distinction how to decide which functions to be members of a class and which not How is your attitude (Your general way from your experiences ...) "If the...
24
8179
by: Jeremy J Starcher | last post by:
While reading c.l.j, I've noticed that some people prefer and indeed even recommend the use of "window.alert()" over "alert()". I can't find any technical reason to make this distinction, and...
0
7259
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,...
0
7158
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
7535
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...
1
7098
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...
0
7523
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5085
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...
0
4745
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...
0
3221
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
455
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...

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.