In This Chapter -
Defining Classes -
Encapsulation and Information Hiding -
Adding Field and Property Members -
Adding Methods to Classes -
Adding Class Events -
Defining Nested Classes -
Creating Instances of a Class -
Summary The ability to define a class and create instances of classes is one of the most important capabilities of any object-oriented language. Until recently Visual Basic didn't really support object-oriented classes. Though VB6 modules were called class modules, they were really interfaces in the Common Object Model (COM) sense of the word. This means that VB6 didn't support the class idiom and didn't support inheritance, another powerful benefit of object-oriented languages. The key difference between interfaces and classes is inheritance. Each implementation of a VB6 interface (class module) required that you implement all of the public methods for that interface. Classes, as opposed to interfaces, support inheritance. Inheritance means that subclasses include the fields, properties, methods, and events of the parent class. By building classes as extensions to existing classes, you can extend and expand existing code bases. Both object-oriented classes and COM interfaces afford developers powerful idioms for writing and managing advanced solutions. Both interfaces and classes have beneficial uses, and now that both are implemented in Visual Basic .NET, Microsoft has made revisions to the interface and class idiom to prevent ambiguity. Both interfaces and classes have distinct grammar rules. This chapter introduces the revised grammar for interfaces and the powerful features of the new class idiom, including inheritance, polymorphism, overloading, and overriding methods. In addition, this chapter provides more examples of exception handling and multithreading in Visual Basic .NET. |