Solved

Preventing a function from being inherited

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
.NET 2008 VB and C# 6 46
Help with error in Query 2 37
VB.Net - String Manipulation Scenario 2 29
Create a button class for use in all vb.net apps 5 13
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 …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

680 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