Difference between Public, Protected, Protected Friend, Private, Friend.

These term determine the visiblity of any classes, properties, or methods you declare.

Public : Declaring a class as Public means you can "see" and instantiate this class in any other classes or subroutines within the same assembly. If you've compiled it into a DLL, referencing assemblies can see it, as well. Declaring a Public Sub / Function or Property means that when its container class is instantiated, the consumer can also see the method or property.

 Private : Private limits the visiblity to a scope. Declaring a private class within a class means that "sub-class" can't be seen from outside of the class. This is also true for methods and properties - they can be seen within the class, but not to any consumers or inheritors.

Protected : This will more likely apply to methods and properties; they won't necessarily be seen outside of the class in which they're declared. However, if a class inherits the container class, that inheritor can see the protected members.

Friend : This applies to classes, methods, and properties. They can be seen within the assembly, but not to any referencing assemblies or even inheritors. (This is the equivalent of "internal" in C#).

 Protected Friend : This is what it seems; classes, methods, and properties declared with this can be seen both within the assembly, as well as by inheritors. They cannot be seen from referencing assemblies. (This is "protected internal" in C#).


Post a Comment