-
classes and inheritance
hi,
Is it possible to inherit another class, but hide all the base classes objects from the users that instantiate our class, i mean so when are object was created , users can access only the events,methods and properties of our class and not the base classes.
( we should still be able to use the base class methods from in our own program, anyway thats why we inherited it )
-
I don't think so, if that is the case then you should just keep a private object of the type you want to inherit. Then you can pick only the properties and what not that you want to expose and hide the others since you aren't actually inheriting anything. Then if you need a method of something from the base class just use the internal private object. Of course that means that the class would not be able to pass as a decendant anymore since it wouldn't be inherited. In other words if you wanted to inherit Listbox and a method called for a listbox argument then your class couln't be passed, unless it was inheriting Listbox.
-
-
no..thats a feature that c++ has and C# and vb.net doesnt have.. although sometime ago i mailed the C# team and they said they would research if they could implement it in C# or not
-
If you are designing the base class yourself, make the members protected.
-
Yeah, that was my thought too - make the base class proterties, etc. protected.
-
Instead of creating a class inheriting from the base class, have the 'base' class as a private member variable of your class.
Code:
Public Class xyz
Private hiddenClass as myOtherClass
Public Sub mySub()
' Can call public members of hiddenClass here, no one outside the object will be able to.
hiddenClass.aSub()
End Sub
End Class
You can do this if the base class is not your own code so you don't expose the other classes code.