18.5. Access Modifiers


An access modifier determines which class methods including methods of other classes can see and use a member variable or method within a class. Table 18-1 summarizes the Visual Basic 2005 access modifiers .

Table 18-1. Access modifiers

Access modifier

Restrictions

Public

No restrictions. Members marked Public are visible to any method of any class.

Private

The members in class A which are marked Private are accessible only to methods of class A.

Protected

The members in class A which are marked Protected are accessible to methods of class A and also to methods of classes derived from class A.

Friend

The members in class A which are marked Friend are accessible to methods of any class in A's assembly.

Protected Friend

The members in class A which are marked Protected Friend are accessible to methods of class A, to methods of classes derived from class A, and also to any class in A's assembly. This is effectively Protected OR Friend (There is no concept of Protected AND Friend.)


The Protected access modifier is used with derived classes, as explained below in the discussion on inheritance. The Friend accessor says that the members are visible to any method within the Assembly. An assembly is a collection of files that appear to the programmer as a single executable (.exe) or DLL.

It is good programming practice to explicitly set the accessibility of all methods and members of your class.




Programming Visual Basic 2005
Programming Visual Basic 2005
ISBN: 0596009496
EAN: 2147483647
Year: 2006
Pages: 162
Authors: Jesse Liberty

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net