Chapter 3. Class Anatomy

only for RuBoard

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 objectbrightness, contrast, hueand 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


Object-Oriented Programming with Visual Basic. Net
Object-Oriented Programming with Visual Basic .NET
ISBN: 0596001460
EAN: 2147483647
Year: 2001
Pages: 112
Authors: J.P. Hamilton

Similar book on Amazon

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