encapsulation - Is there a way to make a value accessible only to the parent of a nested class VB.NET? -


According to the general, OOP paradigm, I think of encapsulation are basically says:

    < Li> If a member is private, then only he can be accessed by the class.
  1. If a member is safe, then he can only be reached to the base class and any derivative classes.
  2. A member is public, it can be accessed by anyone.

If I have a nested class, I have to be accessible to those who can declare a property is nested within the class and the parent class? For example:

  Public Class ContainerClass Public Class NestedClass Integrated Protected Meant '& lt; - It's what I'm thinking of 'myDbl as the protected double' & lt; - is that what I'm thinking about 'Sub New () Myint = 1 myDbl = 1.0 End Sub End Class Private myNestedObject' function illegal 'public sub GrowNestedObject (ByVal multiple integer as New NestedClass) myNestedObject.myInt * = multiplier myNestedObject.myDbl * = multiplier other end sub end class  

in this example, I no longer have access myNestedObject.myInt or myNestedObject.myDbl directly from an example of ContainerClass Those members are private or protected. But let's say I do not want to make them public, because they are also exposed: they can change within the Kantenrclas object ever to declare them friends will still be weak because it allowed to change from anywhere in the application Will go.

What am I going to do here? If not, can someone think a more sensible way of achieving something like this?

There is no way to access directly to it with a combination of modifiers.

The best way I can think of doing this is to include an extra layer of autocracy.

  • Create nested interfaces with personal access. This is only the parent class and nested
  • Apply the interface to the nested class
  • Make sure all the implementations have private access

Now parents and class only The class will gain access to those qualities and methods.

For example:

  Class Parent Private Interface Interface1 ReadOnly Property Field 1 () Integer End Interface Public Class Nested1 Implements Interface1 Private ReadOnly Property Field 1 () Integer Implements Interface1 Go back as far as Field1 42 End of Termination Ending Property Ending Class Sub New () Smooth Child Interface 1 = New Nested DIM x = Child.Field 1 & Sub End Class  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -