Solved

Preventing a function from being inherited

Posted on 2004-09-01
3
195 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now