Conceptually, OOP really isn't that complex. Since both humans and programmers interact with real-world objects and instances every day, it's pretty easy to wrap their minds around the idea of programming with objects. But how easy is it to communicate these object concepts to the computer through the Visual Basic compiler and the .NET Framework? Can it be done without weekly sessions on a shrink's comfy sofa? Duh! It's Visual Basic; of course it's easy.
One reason objects are so easy in .NET is that they have to be. Everything in your .NET program is part of an object, and if everything about .NET was hard, you'd be reading a book on Macintosh development right about now. But it's not too hard because the Visual Basic implementation of objects parallels the conceptual ideas of objects.
Visual Basic uses classes and structures to define objects. I'll talk about structures a little later in the chapter. The
Class keyword starts the definition of a class.
Class Superhero ' ----- Class-related code goes here. End Class
That's most of it: the
Class keyword, and a name for the class ("Superhero," in this case). All classes reside in a namespace (discussed way back in Chapter 1). By default, your classes appear in a namespace that is named after your project. You can alter this in the project properties (to set the top-level namespace for your assembly) and with the
Namespace statement (to indicate relative namespaces from your assembly's top-level namespace). ...