473,769 Members | 8,283 Online
Bytes | Software Development & Data Engineering Community
+ 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 1164
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******@nospa mtwcny.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:
4thLevelClassNa me.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.c om> wrote in message
news:%2******** ********@TK2MSF TNGP11.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(ByV al 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(ByVa l 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.c om> wrote in message
news:u4******** *****@TK2MSFTNG P11.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.c om> wrote in message
news:eU******** ********@TK2MSF TNGP12.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.co m> wrote in message
news:uj******** ******@TK2MSFTN GP12.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

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

Similar topics

51
4074
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 DotNetJunkies.com also. -------------------------------------------------------------------------- YEP, DOTNET JUNKIES REDESIGN....
188
7252
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 - non-deterministic destructors - Objects can't exist on the stack - Type / Reference Types
14
2392
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 implement a common interface? thanks, craig buchanan
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10219
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9865
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8876
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3967
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 we have to send another system
3
2815
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.