Designing Object Models

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

Designing a custom object model can be a tricky business. If you dive in and start coding right away, you might find yourself realizing in the middle of your development process that your design is less than ideal. It pays to take some time to think through an object model, and even draw diagrams and make notes by hand. You might also want to study other object models to understand how they were constructed. When you design an object model, you are taking abstract processes and imposing concrete relationships upon them. In essence, you are creating artificial conceptual divisions for your code.

In This Section

  • Planning the Object Model
    Begin by determining how many objects and collections you must have and naming all of them.
  • Creating Collection Classes
    You can represent a collection with a class module, and use the collection to organize objects of the same type.
  • Relating Objects with Object Properties
    If an object contains a collection or another object, you must create an object property that returns a reference to the object or collection that it contains.
  • Sharing Code by Using Interfaces
    If two or more objects share common functionality, consider whether you can implement an interface that the objects can share.
  • Custom Classes and Objects
    If you have never used class modules to build custom objects before, this section covers the concepts that you must understand to design, build, and use custom objects with their own methods and properties.
  • Why Build Your Own Objects?
    Build entire custom object models that involve complex code behind the scenes, but that present a relatively simple and intuitive object syntax to the programmer.
  • Basic Class Concepts
    Become familiar with using class modules to build custom objects, and learn the basics of adding a class to your project, creating an instance of a class in memory, and constructing properties and methods.
  • Creating Property Procedures
    Public module-level variables in a class module function as properties of an object.
  • Creating Events and Event Procedures
    Take advantage of simple to create events procedures and use ThisDocument, ThisWorkbook, or SheetN objects.
  • Extending Objects Through Interfaces
    Suppose that in the process of designing your application, you decide that you want to create several objects that are closely related, and, in fact, require at least some of the same properties and methods.
  • Creating Custom Objects for Web Pages
    There are two ways to create objects for Web pages that are similar to custom objects created in Microsoft® Visual Basic® for Applications (VBA): by creating scriptlets, and by using Microsoft® Internet Explorer version 5 and later behaviors.