Results 1 to 7 of 7

Thread: classes and inheritance

  1. #1

    Thread Starter
    Registered User
    Join Date
    Apr 2003
    Posts
    61

    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 )

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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.

  3. #3

    Thread Starter
    Registered User
    Join Date
    Apr 2003
    Posts
    61
    thanks

  4. #4
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    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
    \m/\m/

  5. #5
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    If you are designing the base class yourself, make the members protected.

  6. #6
    Fanatic Member VBCrazyCoder's Avatar
    Join Date
    Apr 2003
    Posts
    681
    Yeah, that was my thought too - make the base class proterties, etc. protected.

  7. #7
    Lively Member
    Join Date
    Feb 2003
    Location
    UK
    Posts
    95
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width