Class Semi Specification

Prior to coding any class, consider what kind of public face or interface the class should have. This decision is very important. Once you've decided on an interface, making any changes may break any procedures that use the class. The only "safe" changes to a class interface are additions to the class— new methods or properties. The bottom line is that a switching cost (in terms of time and effort) is associated with changing a class interface. The more procedures that use a class, the higher the switching cost of changing the interface.

As a collection-type class, the Settings class should implement many of the common features of a collection object. Table 12.1 shows the members needed for the Settings class. One member that may stand out to you is the ItemByValue method. I've encountered instances in which I need to perform a reverse lookup, meaning I must retrieve a Setting according to its value instead of its name.

Table 12.1: Members of the Settings Class

Member Name





To add a new Setting to the collection



To count the number of settings



To delete all of the settings



To return a Setting object by index number or name



To return a Setting object by setting value

You may wonder about my choice of member type for the Item member. If you browse through the various Item members for all of the Excel classes that implement this member (Figure 12.1), you'll find that about half implement Item as a property and half implement it as a method.

Was this article helpful?

0 0

Post a comment