Solved

Preventing a function from being inherited

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

770 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