Inheritance...again...

JaedenRuiner

Well-known member
Joined
Aug 13, 2007
Messages
340
Programming Experience
10+
Okay,

I am just curious if there is anyway to truly override the visibility scope of a property/method of an inherited class. For Example:

VB.NET:
Class1.vb
---------
public class Class1
  public sub Add(item as TItem)
  end sub
end class

Class2.vb
---------
public class Class2
  protected shadows sub Add(item as TItem)
   mybase.add(item)
  end sub
  
  public shadows sub add(item as TData)
    dim t as new TItem(item)
    add(t)
  end sub
end class

Form1.vb
---------
dim x as new class2()
x.add -> should only allow adding of TData, not TItem

This in and of itself does not work, for the x variable defined in Form1 class, is able to see both the add() methods. i want to completely hide the inherited add() method so that the only visible one is the one that I choose in my implementation of the inherited class...if it's possible.

Thanks
Jaeden "Sifo Dyas" al'Raec Ruiner
 
Use the Private/Protected access level to hide a member. When you hide a member by shadowing access level you also need to supply another Public (or Friend) member with same name and different signature, else the base method is resolved. This you have done with add(TData), and "x" in your case is only able to see this method.
You can't hide it completely because user can always cast the object to inherited type and use the base methods.
 
Back
Top