CHAPTER 13 n THREADING 316
VB 2008 Best Practices
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 best practices useful for designing types to meet a specific
purpose.We will present these practices as a set of checklists, or recipes, that 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.
Overall, this 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, each partition
concludes with a checklist to be used as a guide when designing new types.
Reference-Type Best Practices
When creating reference types, you should consider what behaviors will be required of the
new type you??™re creating. You should ask yourself several questions before you create a new
type. For example, will you allow your class to be derived from? Is your new type going to be
cloneable? Does your object need a finalizer? What does it mean to compare two references of
this object??™s type for equality? Does your new type support ordering if instances of it are
placed in a collection?
Default to NotInheritable Classes
When you create a new class, automatically mark that class NotInheritable and only remove
the NotInheritable keyword if your design requires the ability to derive from your class.
Pages:
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514