home movie radio music chord lyrics book game Dictionary clip
HOME HAND MADE RADIO SHOP CHORD LYRICS BOOKS GAME Dictionary Clip
only for RuBoard Previous Section Next Section

Chapter 3. Class Anatomy

Encapsulation is the idea that data and the functions that manipulate that data are kept together. In Visual Basic .NET, encapsulation is achieved with the class, which can be thought of as the blueprint of an object. Classes contain member variables that are used to hold the state of an object—brightness, contrast, hue—and member functions (also known as methods) that describe the behavior or operations that can be performed on the object: turn on, turn off, or change the channel. They also are a source of events, which notify clients on the current affairs of the object.

Figure 3-1 illustrates the basic structure of a class, which contains four primary entities: member variables, methods (or member functions), properties, and events. As Example 3-1 shows, the class can exist as part of a namespace (or not).

Figure 3-1. Class overview
figs/OOP_0301.gif
Example 3-1. Structure of a class block
Namespace [Namespace Name]
   
Public Class [Class Name]
   
    'Member variables
   
    'Methods
   
    'Properties
   
    'Events
    
End Class
   
End Namespace

Each class entity (with the exception of events) comes in two distinct flavors, instance or shared. Instance variables, methods, and properties operate on a specific instance of a class. When an object is created (instantiated), it receives its own copy of all the member data defined by the class. All method (and property) calls are made through that specific instance.

Example 3-2 contains a shared method named Hello. Shared entities are mutual across all class instances, so you don't need an actual instance of the class to call the method:

Console.WriteLine(World.Hello( ))

In addition to being associated with a data type, all class entities (events included), and the class itself, are associated with an access modifier. These modifiers determine whether a client can access the entity or if the entity is available only internally within the object, in its descendents, or in the executable in which it is defined.

only for RuBoard Previous Section Next Section