Extending the Bridge

Now suppose that we need to make some changes in the way these lists display the data. For example, you might want to have the products displayed in alphabetical order. You might think you'd need to either modify or subclass both the list and table classes. This can quickly get to be a maintenance nightmare, especially if more than two such displays eventually are needed. Instead, we simply make the changes in the extended interface class, creating a new sortBridge class similar to the...

State Pattern in VBNET

The State pattern in VB7 is similar to that in VB6. We use the same interfaces for the Memento and Drawing classes. Sub setSelected ByVal b As Boolean Sub draw ByVal g As Graphics Sub move ByVal xpt As Integer, ByVal ypt As Integer Function contains ByVal x As Integer, _ ByVal y As Integer As Boolean Sub setFill ByVal b As Boolean Property rects As vbpatterns.Rectangle End Interface However, there is some advantage in creating a State class with empty methods and overriding only those that a...

The Flyweight Pattern

In this chapter we take up the Flyweight pattern, which is used to avoid the overhead of large numbers of very similar classes. There are cases in programming where it seems that you need to generate a very large number of small class instances to represent data. Sometimes you can greatly reduce the number of different classes that you need to instantiate if you can recognize that the instances are fundamentally the same except for a few parameters. If you can move those variables outside the...

Writing a Prototype in VB7

In VB7, we can write more or less the same code. The major changes are that we will use ArrayLists and zero-based arrays, and that we can write a base SwimData class from which we can inherit a number of useful methods. We create the base SwimData class without a sort method and specify using MustInherit for the class and MustOverride for the method that you must provide an implementation of sort in the child classes. Protected Swimmers As ArrayList Private index As Integer 'constructor to be...