473,382 Members | 1,407 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Property Scope

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
Nov 21 '05 #1
1 1105
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
"Rlrcstr" <rl*****@msn.com> wrote in message news:%2***************@TK2MSFTNGP12.phx.gbl...
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
Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Codemonkey | last post by:
Just a silly question, but why can't you overload a writeonly property with a readonly one? Surely the compiler can tell the difference of which one to call at compile time, depending on if it is...
11
by: Just Me | last post by:
This doesn't work. I guess New is needed someplace but I don't know where? Public Property Filters() As ArrayList Get Filters.Add(cboFilter.Text)
5
by: Harold Hsu | last post by:
Hi all, What's the default access type of a property declared in an interface? The one I'm looking at is IBindingList: Public Interface IBindingList .... ReadOnly Property AllowEdit As...
2
by: Don | last post by:
If you expose an object as a property in a VB.NET class, like so: public class MyClass private obj as NestedClass Public Readonly Property NestedObj as OtherClass Get return obj End Get...
15
by: Sam Kong | last post by:
Hello! I got recently intrigued with JavaScript's prototype-based object-orientation. However, I still don't understand the mechanism clearly. What's the difference between the following...
6
by: David Hearn | last post by:
I have a property in a user control that I am setting: Private strPageName as String Public Property PageName() as String Get Return strPageName End Get Set(byVal Value as String)...
2
by: Saran | last post by:
Hi, Below is my scenario... I want to restrict my clients to access one of my class property in ReadOnly mode. At the same time as an author of the component i would like to have read-write...
9
by: garyusenet | last post by:
Hello I'm trying to get to grips with variable scope. I have a very basic programme i'm working on - and am once again being confused by scope of variables. I am just trying to write a new...
6
by: forest demon | last post by:
i have a custom control that gets loaded at runtime. i need to be able to access a property of a control thats part of the main form, through the clcik event of the custom control. i may be...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.