O'Reilly logo

Object-Oriented Programming with Visual Basic .NET by J.P. Hamilton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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
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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required