March 1, 2021
Hot Topics:

Beginning Objects in VB - Part 3

  • By Sam Huggill
  • Send Email »
  • More Articles »

Right. Now that Ive given you a lecture on the ideas behind an object model, I'll give you some tips for building your program around a model.

Firstly, use VB's built in tools! There's no point having a rich design environment if you don't use it to the full. Visual Basic includes a very good tool for helping you deal with class modules. The VB Class Builder Wizard is what you want to be using, and it's really very good. To load it up click Project, Add Class Module and select VB Class Builder.

You'll see from the file menu that you can either create a new class module or collection. Now think of it like this: you use a new class module for an individual user, and a collection for a group of users. So say your class is called User then you can make a collection class called Users.

This follows a logical pattern that is also seen in most modern applications. What I would suggest you do now is to carry out what Ive described and get used to using the Class Builder.

But don't worry; I'm not going to leave you to build your own object model just yet! Here are a few more tips.

Building your object model should be about thinking out what you program does, and breaking it down into logical parts. Think about a customer database. You're going to have customers, and each customer is going to have a pre-defined set of properties, such as name, address etc.

Going back to the idea of collections, look at what Ive just said. There are customer(s) and a customer. Here we can see that the plural of customer will be our collection, and the individual item will be our customer. So when you think about it, you can see the obvious areas that can be broken down into collections and individual items.

If you're having problems thinking about these things, then it highlights problems in your application design. If we carry this out at the beginning when planning our program, we will be able to prevent the failure of our project.

So planning out your object model will help you write reusable code, help other developers to use your program, clarify your application plan and even make the coffee (well, maybe not yet, but thats the topic of my next article!)

Hopefully by now I've bored you stiff with enough information to make you actually plan out your object model. But as always, an example helps. So lets have one then!

Page 3 of 4

This article was originally published on November 20, 2002

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date