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

Another question on Inheritance

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


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

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

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

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

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

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

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

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

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

P: n/a
Catch you later Joe, Enjoy the trip.

Regards,
Fergus
Nov 20 '05 #11

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

Replies have been disabled for this discussion.