Canonical Forms

Many object-oriented languages—VB included—do not offer anything to force developers to create well-designed software. In much the same way that design patterns evolved, the development community has identified some canonical forms useful for designing types to meet a specific purpose. These canonical forms are merely checklists, or recipes, you can use while designing new classes. Before a pilot can clear an airplane to back out of the gate, he must go through a strict checklist. The goal of this chapter is to identify such checklists for creating robust types in the VB world.

When you explore these checklists, you need to consider what sorts of behaviors are required of objects of the new type you’re creating. For example, is your new type going to be cloneable? In other words, can it be copied? Does your new type support ordering if instances of it are placed in a collection? What does it mean to compare two references of this object’s type for equality? In other words, do you want to know if the two references refer to the same instance? Or do you want to know if the two instances referred to have exactly the same state? These are the types of questions you should ask yourself when you create a new type.

Note: This chapter is rather long, but it’s important to keep so much useful and related information together. Overall, the chapter is sectioned into two partitions. The first partition covers reference types, while the latter covers value types. We cover the longer partition on reference types first, since some material applies to both reference types and value types. Finally, the chapter concludes with a checklist to go through when designing new types.