Share via


Visual Basic Concepts

Programming with Your Own Objects

You can start using objects gradually, finding useful tasks for which combining code and data is an advantage. You can use the functionality of these objects by declaring object variables, assigning new objects to them, and calling the objects' properties and methods.

As you add more and more objects to your programs, you'll start to see relationships between them. You can begin making program design more dependent on objects and their relationships, and you can begin using more robust techniques — like creating custom collection classes — for expressing those relationships in code.

At some point, you'll suddenly see how linking objects together changes the very nature of your program, and you'll be ready to start designing object-based programs from the ground up.

The following topics provide an overview of these evolutionary changes in your coding style. Read them now, to give yourself a rough picture of where you're headed, and read them again when your ideas of object-based programming begin to gel.

  • Object References and Reference Counting   The more you use objects, the more you need to manage your object references, so your component frees memory when it should and shuts down in an orderly fashion.

  • Object Models   How do the objects you create from your classes relate to each other? Object models express relationships in terms of containment — that is, one kind of object contains one or more of another kind. This is a powerful organizing principle for your programs.

  • Creating Your Own Collection Classes   Exposes some problems with the Visual Basic Collection object, and shows how you can create your own collection classes — that is, classes that delegate to a Collection object (thus gaining the ability to work with For Each … Next) while providing increased robustness and more functionality.

For More Information   ActiveX components open up yet another dimension of code reuse and object-based programming. If you have the Professional or Enterprise Edition of Visual Basic, you can begin to explore that dimension through Creating ActiveX Components in the Component Tools Guide.