Compartir a través de


Visual Basic Concepts

Creating Your Own Collection Classes

There are three general approaches you can take to implementing object containment using collections. Consider the Employees collection of the SmallBusiness object discussed in "Object Models." To implement this collection you might:

  • In the SmallBusiness class module, declare an Employees variable As Collection, and make it Public. This is the cheap solution.

  • In the SmallBusiness class module, declare an mcolEmployees variable As Collection, and make it Private. Give the SmallBusiness object a set of methods for adding and deleting objects. This is the least object-oriented of the three designs.

  • Implement your own collection class, by creating a collection class module named Employees, as described later in this chapter. Give the SmallBusiness object a read-only property of the Employees class.

The strategies are listed in order of increasing robustness. They could be characterized as the house of straw, house of sticks, and house of bricks approaches.