Section 2.4. Types and Objects


2.4. Types and Objects

Pretty much everything in a .NET application is contained in a type. Types include:

  • Classes, which are basically collections of data values, and the related code that manages that data. Usually a class has both data and code, but a particular class might just have either data or code. In Visual Basic, a Module is a variation of a class.

  • Interfaces, which are class "skeletons." Interfaces define the basic structure of a class but without the actual implementation. They are useful for defining a common layout of features to be shared by many related classes.

  • Delegates, which .NET uses to implement its event-driven infrastructure.

  • Enumerations, which are collections of named numeric elements.

  • Value types and reference types. Normally, when you create an object (an in-memory instance of a class), that object sits in memory somewhere, and your object variable contains the memory location of the object block. (It's like a pointer, for those familiar with the C language parlance.) These are reference types. The .NET type system also supports value types. A value type variable stores the actual data value instead of a memory address to the true location of the data.

  • Other similar things. You can subdivide the type system forever, but everything is eventually called a type.

From the Visual Basic point of view, all types are really classes. Of course, all data objects are instances of classes, but even your source codeeven your Sub Main routineis part of a class, and it must be part of a class to be part of a .NET application.

Classes define a chunk of related data and functionality. When you design a class, you are saying, "I'm planning on creating an object that has these features and that stores this type of data and information." Objects are the actual in-memory instances of a class. For a much richer description of objects and other object-oriented concepts, see Chapter 3.

The root of the type hierarchy is the System.Object class. All new classes you design eventually tie back to the System.Object class. This class provides some basic functionality required of all classes and provides a convenient way to generically identify any object in your application.




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

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