Friday, December 28, 2007

OOP: VB.Net Encapsulation

The following describes how OO programming techniques are implemented in Visual Basic code. This article is a great index, with many examples.

Encapsulation enables the developer to hide information. Information is hidden, not as much to limit access, but to make an object easier to use for its consumers.

Visual Basic enables access to information within classes through Access Modifiers. Access Modifiers determine who has access to what.
  1. Private - often reffered to as member variables and designated with an "m". Only available in the code where the variable or method was declared.
  2. Public - accessable anywhere within the application
  3. Friend - accessable only by members of the class where it was declared
  4. Protected - accessable only by members of the class where it was declared, or by members of the inheriting class.
  5. Shared - used in a base class. The value of a shared property will change accross all instances of the class, even when the class has several implementations.
Advise is given to make as little as possible public. The more public properties and methods, the more confusing the public interface could be.

No comments: