473,487 Members | 2,622 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Another question on Inheritance

Public MustInherit Class My3rdLevelClass

Inherits GeneratedClass

Public Shared Function GetSomething() As String

Return "Something"

End Function

In the sample above I have declared the class as MustInherit.

I have questions about the scope of the GetSomething method.
I was able to call it directly from a class in the same project.
What should it be set to in order to allow a class that inherits it the
ability to "use it" but that does not allow anyone to call it directly?

--
Joe Fallon


Nov 20 '05 #1
11 1145
Hi Joe,

That's the Protected keyword you're after there. For methods
that are available to the current class and all derived classes only.

Regards,
Fergus
Nov 20 '05 #2
* "Joe Fallon" <jf******@nospamtwcny.rr.com> scripsit:
Public MustInherit Class My3rdLevelClass

Inherits GeneratedClass

Public Shared Function GetSomething() As String

Return "Something"

End Function

In the sample above I have declared the class as MustInherit.

I have questions about the scope of the GetSomething method.
I was able to call it directly from a class in the same project.
What should it be set to in order to allow a class that inherits it the
ability to "use it" but that does not allow anyone to call it directly?


Set its modifier to 'Protected'.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #3
Fergus,
I tried using Protected (and Protected Friend) but it didn't seem to work
right.

As you recall I have 4 levels of classes.
When they are all Public Shared, they work fine.

I just use syntax like:
4thLevelClassName.SomeMethod
(SomeMethod is Public and is in Level 1,2 or 3)

But when I made SomeMethod a Protected function, the 4th level could not
"see" it even though it inherited it.

I think I am missing something here.
Can you enlighten me?

--
Joe Fallon
"Fergus Cooney" <fi*****@post.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi Joe,

That's the Protected keyword you're after there. For methods
that are available to the current class and all derived classes only.

Regards,
Fergus

Nov 20 '05 #4
Hi Joe,

It depends on what you mean by 'see'. Do you mean that
1) Intellisense can't see it or
2) Level4 can't access it (within itself) and gives a compiler
warning, or
3) users of the Level4 class can't access it?

It would be handy to post some code as well.

Cheers,
Fergus
Nov 20 '05 #5
Fergus,
The first 2 for sure.

There was no intellisense for the method and the compiler underlined the
method and said it could not be accessed because it was Private.

Sample code:

Level 1
Protected MustInherit Class Base

Protected Shared Function DoSomething(ByVal Source As String) As String

End Function
================================================
Level 2
Protected MustInherit Class GeneratedStuff

Inherits Base

Protected Shared Function DoSomethingElse(ByVal Source As String) As String

End Function
================================================
Level 3
Protected MustInherit Class HandCodedStuff

Inherits GeneratedStuff

Protected Shared Function IWroteThis(ByVal Source As String) As String

End Function
================================================
Level 4 (implements same functionality as Level 3 but also allows customized
changes by overriding methods or creating new ones that are specific to a
single client. Level 3 functionality is for all clients.)
Public MustInherit Class FinalLevel

Inherits HandCodedStuff

Public Shadows Function DoSomethingElse(ByVal Source As String) As String

End Function


--
Joe Fallon

"Fergus Cooney" <fi*****@post.com> wrote in message
news:u4*************@TK2MSFTNGP11.phx.gbl...
Hi Joe,

It depends on what you mean by 'see'. Do you mean that
1) Intellisense can't see it or
2) Level4 can't access it (within itself) and gives a compiler
warning, or
3) users of the Level4 class can't access it?

It would be handy to post some code as well.

Cheers,
Fergus

Nov 20 '05 #6
Hi Joe,

Unfortunately that's the outline-code that you posted before showing what
you'd like to do. I need to see how you're actually putting it into practice
so that I can spot where it's going wrong.

With the code, could you do me a favour? Copy it from your project into
NotePad. Then cut it from there and paste it into the message. This should
prevent all the double lines (which I have to remove before I can compile the
code). If it's a lot of code, I'd prefer an attachment - zip or txt file - as
this will preserve the line lengths as well.

Regards,
Fergus
Nov 20 '05 #7
I don't have a valid code sample. handy.
Since it didn't work I re-wrote it.

Perhaps tomorrow I can put together a small project.
If so, I will zip it up and send it to ... where?

Thanks for your willingness to help!
--
Joe Fallon


"Fergus Cooney" <fi*****@post.com> wrote in message
news:eU****************@TK2MSFTNGP12.phx.gbl...
Hi Joe,

Unfortunately that's the outline-code that you posted before showing what you'd like to do. I need to see how you're actually putting it into practice so that I can spot where it's going wrong.

With the code, could you do me a favour? Copy it from your project into NotePad. Then cut it from there and paste it into the message. This should
prevent all the double lines (which I have to remove before I can compile the code). If it's a lot of code, I'd prefer an attachment - zip or txt file - as this will preserve the line lengths as well.

Regards,
Fergus

Nov 20 '05 #8
Hi Joe,

Lol, I'm happy to help, as the saying goes. :-))

I'd prefer it to be sent here as it's easier for me. It also allows anyone
else interested to have a look. If it's only a few K that's fine - many
messages are longer. You could post in-line code but you're kindly making it
smaller by zipping. That seems fair to me

If you feel uncomfortable with that, though, my email address
fi****@post.com should be working (it gets enough spam!). But because it <is>
a spam destination address, I only check it when I know there's something
waiting there. So you'll have to send it there then let me know here. (Which
is one reason why I'd prefer the zip here). LOL. Trust your instincts. ;-)

Regards,
Fergus
Nov 20 '05 #9
I didn't forget.
Swamped at work.
I have a business trip coming up too so I may not get to it for a week or
so.
It is at the top of my list when I get time to work on it though!

I will send the e-mail and post a note here.
I dislike attachments in Newsgroups unless they have Binary in their title.
It is unfair to those users who don't want to waste the time and bandwidth
to download files.

Thanks!
--
Joe Fallon

"Fergus Cooney" <fi****@post.com> wrote in message
news:uj**************@TK2MSFTNGP12.phx.gbl...
Hi Joe,

Lol, I'm happy to help, as the saying goes. :-))

I'd prefer it to be sent here as it's easier for me. It also allows anyone else interested to have a look. If it's only a few K that's fine - many
messages are longer. You could post in-line code but you're kindly making it smaller by zipping. That seems fair to me

If you feel uncomfortable with that, though, my email address
fi****@post.com should be working (it gets enough spam!). But because it <is> a spam destination address, I only check it when I know there's something
waiting there. So you'll have to send it there then let me know here. (Which is one reason why I'd prefer the zip here). LOL. Trust your instincts. ;-)

Regards,
Fergus

Nov 20 '05 #10
Catch you later Joe, Enjoy the trip.

Regards,
Fergus
Nov 20 '05 #11
Fergus,
I found some time today and built a sample and e-mailed it to you.
Traveling tomorrow til Thursday.
Thanks!
--
Joe Fallon
"Fergus Cooney" <fi****@post.com> wrote in message
news:OF**************@TK2MSFTNGP10.phx.gbl...
Catch you later Joe, Enjoy the trip.

Regards,
Fergus

Nov 20 '05 #12

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

Similar topics

51
3997
by: nospam | last post by:
THIS IS the DOTNETJUNKIES MESSAGE ------------------------- We're Sorry As many of you know we have recently launched SqlJunkies.com. We have overhauled our runtime and will be using it on...
188
7036
by: christopher diggins | last post by:
I have posted a C# critique at http://www.heron-language.com/c-sharp-critique.html. To summarize I bring up the following issues : - unsafe code - attributes - garbage collection -...
14
2367
by: Craig Buchanan | last post by:
If I have two custom vb.net classes, where 80% of the properties are alike and there is one method with a matching signature, can i cast between one and the other? do i need to have each class...
0
7137
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
7181
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...
0
7349
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
4874
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
4565
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
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1381
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 ...
1
600
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
267
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.