Writing a Memento in VBNET

We can write almost the same code in VB7. However, while VB7 does not provide completely privileged access to class variables or properties, it does provide the friend keyword, which restricts access to a property or variable to code in the current project. For our visRectangle class, we can declare the rect property as having a friend modifier 'Property methods used to save and restore state Friend Property rects() As vbpatterns.Rectangle This is almost the same as having public access to the...

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...