Property Scope

R

Rlrcstr

Is there any way to restrain member visibility to within a class? I have a class with a few classes defined within. (Note that they aren't inheriting from the class, just encapsulated within it.) I want the inner classes to be able to share data with the outer class, but not outside of it. Protected only seems to affect derived classes. And Friend allows the stuff to be seen anywhere in the application.

I'm probably asking too much, but I want the inner class to be seen publicly, but save a few of it's members only for access by the outer class:

Public Class OuterClass
Private _somePrivateVar <- Only from within OuterClass
Public _somePublicVar <- Can be seen by everyone.

Public Class InnerClass
Public _somePublicVar <- Can be seen by everyone.
<?????> _someOtherVar <- Can be seen by OuterClass, by not beyond.
End Class
End Class

Is this possible?

Thanks.

Jerry
 
R

Ray Cassick \(Home\)

I would keep the internal classes private and then create accessor properties in the outer class that allow you to access the those properties of the inner class you wish to expose higher.

ALL var access should be through properties anyway. You should not make vars public in scope.

This is really rough (typed into a text editor and not a code editor), but you shoul dget the idea...






Public Class OuterClass

Private mSomePrivateVar As Integer
private mPrivateClassInstance As InnerClass

Public Sub New()
mPrivateClassInstance = New PrivateClassInstance

End Sub

Public Property PrivateVar As Integer
Get
Return mSomePrivateVar

End Get
Set (value As Integer)
mSomePrivateVar = value

End Set
End Property

Public Property InnerValue As Integer
Get
Return mPrivateClassInstance.PrivateVarOne

End Get
Set (value As Integer)
mPrivateClassInstance.PrivateVarOne = value

End Set
End Property


Private Class InnerClass
Private mSomePrivateVar As Integer
Private mAnotherPrivateVar as Integer

Public Sub New()

End Sub

Public Property PrivateVarOne As Integer
Get
Return mSomePrivateVar

End Get
Set (value As Integer)
mSomePrivateVar = value

End Set
End Property

Public Property PrivateVarTwo As Integer
Get
Return mAnotherPrivateVar

End Get
Set (value As Integer)
mAnotherPrivateVar = value

End Set

End Property

End Class

End Class
Is there any way to restrain member visibility to within a class? I have a class with a few classes defined within. (Note that they aren't inheriting from the class, just encapsulated within it.) I want the inner classes to be able to share data with the outer class, but not outside of it. Protected only seems to affect derived classes. And Friend allows the stuff to be seen anywhere in the application.

I'm probably asking too much, but I want the inner class to be seen publicly, but save a few of it's members only for access by the outer class:

Public Class OuterClass
Private _somePrivateVar <- Only from within OuterClass
Public _somePublicVar <- Can be seen by everyone.

Public Class InnerClass
Public _somePublicVar <- Can be seen by everyone.
<?????> _someOtherVar <- Can be seen by OuterClass, by not beyond.
End Class
End Class

Is this possible?

Thanks.

Jerry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top