By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,552 Members | 905 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,552 IT Pros & Developers. It's quick & easy.

Question on "Shadowing"

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
"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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.