Team-Fly team-fly    

ADO.NET Programming in Visual Basic .NET
By Steve  Holzner, Bob  Howell

Table of Contents
Chapter 2.   Object-Oriented Programming in Visual Basic .NET

Encapsulation means that all of the members of a class and the processes to be performed on those members must be contained within the class they reside in. Another way of saying this is that the class must contain everything it needs to store and operate in the data it defines. That means, for example, if a class contains date data, it must also contain the information and procedures required to format and print the data, if that is a required function of the class. In pure form, it also means that the class should not have to rely on any external data or procedures, but be entirely self-contained. In this sense, the class can be seen as a complete program unto itself.

Besides containing data and the procedures to be performed on the data, the class also must have a way of sharing this information and knowledge with the outside world. In OOP parlance, this is called the interface. The mechanism used to control how much of this information is shared is called the access control system. In VB .NET, this is implemented via access control modifiers that can be used for classes and members.

When applied to members they mean:

  • Private This means that the member variable or procedure is accessible only from within this class. It is invisible to other classes.

  • Public The member is accessible from any other class with no restrictions. Note that this does not mean it is a global variable; the class containing the member still has to be instantiated .

  • Protected This is similar to private; except that the member can be accessed from any inherited classes as well as the current class. It cannot be accessed from other classes.

  • Friend Friend members are similar to public members except they can only be accessed from within the same assembly. As long as the class is declared in the current project, you can see friend members, but if the class is declared in another project, the friend members are invisible.

You can combine protected and friend. This causes the member to be accessible in inherited classes outside the current project, but it still retains friend access within the project of the inherited class. It will be accessible from other classes within the project of the inherited class but not from outside the project.

When applied to classes or structures they mean:

  • Private The class (or structure) is accessible from only within the current class. It cannot be declared outside the class. Valid for nested classes only.

  • Public The class is accessible with no restrictions.

  • Protected Applies to nested classes only. The nested class is available to inherited classes, but not outside the branch of the inheritance tree.

  • Friend The class is available inside the current project, but not outside it.

As with member access modifiers, Protected and Friend can be combined with similar behavior as for members, but only on nested classes.

Team-Fly team-fly    

ADO. NET Programming in Visual Basic. NET
ADO.NET Programming in Visual Basic .NET (2nd Edition)
ISBN: 0131018817
EAN: 2147483647
Year: 2005
Pages: 123

Similar book on Amazon

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