Solved

Preventing a function from being inherited

Posted on 2004-09-01
3
199 Views
Last Modified: 2010-04-23
I have a class

Public Class Product
   Properties.......
   Sub Save
        save the record to the database.......
   End Sub
End Class

Public Class ProductOrder
   Inherits Product

   More properties.....
End Class

The only catch is that I don't want the Save() to be accessable in my ProductOrder Class  I can't however make the Save() Private because I need to be able to call it when working directly with the Product Class.

Is there a way to do this?

Thanks
0
Comment
Question by:dbashley1
3 Comments
 
LVL 3

Assisted Solution

by:GrumbleBot
GrumbleBot earned 125 total points
ID: 11953280
hmmm. By wanting to access Save() mthod from elsewhere in your program you need it to be public as you say. Well this means that any part of your program will be able to use it including ProductOrder. So even if not inherited ProductOrder will still be able to access the Save() method because it is public.

So I gues my question then would be if your Save() method is public then why wouldn't you let ProductClass inherit the method. As it can call it anyways because you are making it public.

Not sure If I confused you with this or not.

Hope this helps.

Good Luck
0
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 125 total points
ID: 11953330
I will need more information on this but it sounds to me like you actually need another class to act as the base for product and productorder (which would not define a save method... then the product sub class would define the save method.

you cannot do what you are discussing because it would break polymorphism ... by inheriting product, your class must have all of the same public contracts as a product because it can be treated as a product.

aside from that why do you not want the save method on product order
0
 

Author Comment

by:dbashley1
ID: 11954175
gregoryyoung,

The save does different things.  I guess I could just override the save() and handle it that way.  I will try that.

Thanks for your help
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question