Solved

Preventing a function from being inherited

Posted on 2004-09-01
3
202 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

636 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