Introduction to classes in Visual Basic

Classes are the code definitions for objects. Classes interact with each other with the help of three key ingredients:

  • Properties: Properties allow you to access an object’s data. Some properties may be readonly,
    so they cannot be modified, while others can be changed.
  • Methods: Methods allow you to perform an action on an object. Unlike properties, methods are used for actions that perform a distinct task or may change the object’s state significantly. For example, to open a connection to a database, you might call the Open() method of a Connection object.
  • Events: Events provide notification that something has happened. If you’ve ever programmed an ordinary desktop application in Visual Basic, you know how controls can fire events to trigger your code. For example, if a user clicks a button, the Button object fires a Click event, which your code can react to. ASP.NET controls also provide events.

Classes contain their own code and internal set of private data. Classes behave like black boxes, which means that when you use an object, you shouldn’t waste any time wondering how it works internally or what low-level information it’s using. Instead, you need to worry only about the public interface of a class, which is the set of properties, methods, and events available for you to use. Together, these elements are called class members.


You may also like...