Home > Store > Programming > Windows Programming

Visual Basic Design Patterns: VB 6.0 and VB.NET

Register your product to gain access to bonus material or receive a coupon.

Visual Basic Design Patterns: VB 6.0 and VB.NET

Book

  • Sorry, this book is no longer in print.
Not for Sale

Description

  • Copyright 2002
  • Dimensions: 7-3/8x9-1/4
  • Pages: 512
  • Edition: 1st
  • Book
  • ISBN-10: 0-201-70265-7
  • ISBN-13: 978-0-201-70265-1

Design patterns provide programmers with a convenient way to reuse object-oriented code across projects and between programmers, offering easy, time-saving solutions to commonly recurring problems in software design. A practical guide to writing Visual Basic (VB6 and VB.NET) programs using some of the most common design patterns, Visual Basic Design Patterns is a tutorial for people who want to learn about design patterns and how to use them in their work. This book also provides a convenient way for VB6 programmers to migrate to VB.NET and use its more powerful object-oriented features.

Written from a Visual Basic perspective, this book intends to make you comfortable with using design patterns by laying out the concept of patterns in a practical fashion. Organized as a series of short chapters that each describe a design pattern, Visual Basic Design Patterns provides one or more complete working visual examples of programs using that pattern, along with UML diagrams illustrating how the classes interact. Each example is a visual program that you can run and study on the companion CD making the pattern as concrete as possible. Programmers using this book will see significant improvement in their work by employing the following key concepts:

  • Applying "tried-and-true" object-oriented design patterns in Visual Basic applications.
  • Helping advance programming skills with the power of patterns.
  • Understanding the interactions between classes through the use of UML diagrams.
  • Getting comfortable using design patterns effectively and start using them in day-to-day Visual Basic programming.

The idea behind design patterns is simple: it's a catalogue of common interactions between objects that programmers have found useful, enabling them to quickly and easily employ them in their programs. Visual Basic Design Patterns provides practical advice on how to use these patterns in everyday programming.



0201702657B07122001

Sample Content

Online Sample Chapter

Using Classes and Objects in VB

Downloadable Sample Chapter

Click below for Sample Chapter related to this title:
cooperch03.pdf

Table of Contents



Preface.


Acknowledgements.

I. OBJECT-ORIENTED PROGRAMMING IN VB.

1. What Are Design Patterns?

Defining Design Patterns.

The Learning Process.

Studying Design Patterns.

Notes on Object Oriented Approaches.

VB Design Patterns.

How this Book is Organized.

2. UML Diagrams.

Inheritance.

Interfaces.

Composition.

Annotation.

WithClass UML Diagrams.

Visual Basic Project Files.

3. Using Classes and Objects in VB.

A Simple Temperature Conversion Program.

Building a Temperature Class.

Converting to Kelvin.

Putting the Decisions into the Temperature Class.

Using Classes for Format and Value Conversion.

Handling Unreasonable Values.

A String Tokenizer Class.

Classes as Objects.

Class Containment.

Class Initialization.

Classes and Properties.

Another Interface Example—The Voltmeter.

A vbFile Class.

Programming Style in Visual Basic.

Summary.

4. Object-Oriented Programming.

Building VB Objects.

Creating Instances of Objects.

A VB Measurement Program.

Methods Inside Objects.

Variables.

Passing Arguments by Reference and by Value.

Object Oriented Jargon.

5. Building Your Own VB Control.

A Highlighted Text Field.

Resizing a User Control.

Testing Your HiText Controls.

Adding Properties and Methods to User Controls.

Compiling a User Control.

Summary.

Program on the CD-ROM.

6. Inheritance and Interfaces.

Interfaces.

An Investment Simulator.

Writing the Simulator.

Indicators for Using an Interface.

Reusing Common Methods.

Hidden Interfaces.

Summary.

Programs on the CD-ROM.

7. Introduction to VB.NET.

Syntax Differences in VB.NET.

Improved Function Syntax.

Variable Declarations and Scoping.

Objects in VB.NET.

Compiler Options.

Numbers in VB.NET.

Properties in VB6 and VB.NET.

Shorthand Equals Syntax.

Managed Languages and Garbage Collection.

Classes in VB.NET.

Building a VB7 Application.

The Simplest Window Program in VB.NET.

Inheritance.

Constructors.

Drawing and Graphics in VB.NET.

Tooltips and Cursors.

Overloading.

Inheritance.

Namespaces.

Creating a Square from a Rectangle.

Public, Private, and Protected.

Overriding Methods in Derived Classes.

Overloading and Shadowing.

Overriding Windows Controls.

Interfaces.

Summary.

Programs on the CD-ROM.

8. Arrays, Files and Exceptions in VB.Net.

Arrays.

Collection Objects.

ArrayLists.

Hashtables.

SortedLists.

Exceptions.

Multiple Exceptions.

Throwing Exceptions.

File Handling.

The File Object.

Reading a Text File.

Writing a Text File.

Exceptions in File Handling.

Testing for End of File.

The FileInfo Class.

A vbFile Class.

Programs on the CD-ROM.

II. CREATIONAL PATTERNS.

9. The Simple Factory Pattern.

How a Simple Factory Works.

Sample Code.

The Two Derived Classe.

Building the Simple Factory.

Using the Factory.

Writing the Factory Pattern in VB.NET.

Factory Patterns in Math Computation.

Programs on the CD-ROM.

10. The Factory Method.

The Swimmer class.

The Events Classes.

Straight Seeding.

Circle Seeding.

Our Seeding Program.

Other Factories.

The Seeding Program in VB7.

When to Use a Factory Method.

Programs on the CD-ROM.

11. The Abstract Factory Pattern.

A GardenMaker Factory.

How the User Interface Works.

Creating an Abstract Factory Using VB7.

The Picture Box.

Handling the RadioButton and Button Events.

Adding More Classes.

Consequences of Abstract Factory.

Programs on the CD-ROM.

12. The Singleton Pattern.

Creating Singleton Using a Static Method.

Catching the Error.

Providing a Global Point of Access to a Singleton.

The MSComm Control as a Singleton.

Available Ports.

Writing a Singleton in VB.NET.

Using a Private Constructor.

Error Handling in Our Singleton.

A VB.NET SpoolDemo Program.

The Global Point of Access.

Other Consequences of the Singleton Pattern.

Programs on Your CD-ROM.

13. The Builder Pattern.

An Investment Tracker.

Calling the Builders.

The List Box Builder.

The Checkbox Builder.

Writing a Builder in VB.NET.

The Stock Factory.

The CheckChoice Class.

The ListboxChoice Class.

Using the Items Collection in the ListBox Control.

The Final Choice.

Consequences of the Builder Pattern.

Programs on the CD-ROM.

14. The Prototype Pattern.

Cloning in Visual Basic.

Using the Prototype.

Using the Prototype Pattern.

Additional Methods in Subclasses.

Dissimilar Classes with the Same Interface.

Prototype Managers.

Writing a Prototype in VB7.

Consequences of the Prototype Pattern.

Programs on the CD-ROM.

Summary of Creational Patterns.

III. Structural Patterns.

15. The Adapter Pattern.

Moving Data between Lists.

Using the MSFlexGrid.

Using a TreeView.

The Object Adapter.

Two Way Adapters.

Using Adapters in VB7.

TreeView Adapters for VB.NET.

Adapting a DataGrid.

The Class Adapter.

Two-Way Adapters.

Object versus Class Adapters in VB.NET.

Pluggable Adapters.

Adapters in VB.

Programs on the CD-ROM.

16. The Bridge Pattern.

The visList Classes.

The Class Diagram.

Extending the Bridge.

ActiveX Controls as Bridges.

The Bridge Pattern in VB.NET.

The ListBox VisList Class.

The Grid VisList Class.

Loading the Data.

Changing the Data Side of the Bridge.

Consequences of the Bridge Pattern.

Programs on your CD-ROM.

17. The Composite Pattern.

An Implementation of a Composite.

Computing Salaries.

The Employee Classes.

The Subords Class.

The Boss Class.

Building the Employee Tree.

Self-Promotion.

Doubly Linked Lists.

Consequences of the Composite Pattern.

A Simple Composite.

Composites in VB.

The Composite in VB.NET.

The Enumerator.

Multiple Boss Constructors.

Other Implementation Issues.

Programs on the CD-ROM.

18. The Decorator Pattern.

Decorating a CoolButton.

Using a Decorator.

Using ActiveX Controls as Decorators.

A Decorator In VB.NET.

Nonvisual Decorators.

Decorators, Adapters and Composites.

Consequences of the Decorator Pattern.

Programs on the CD-ROM.

19. The Facade Pattern.

What is a Database?

Getting Data out of Databases.

Kinds of Databases.

ODBC.

Microsoft Database Connection Strategies.

Database Structure.

The DBase Class.

Building the Facade Classes.

The Stores Class.

Building the Stores and Foods Tables.

Building the Price Table.

Building the Price Query.

Summary of the Facade Pattern.

ADO Database Access in VB6.

The ADO Connection.

Adding and Seeking Rows Table Rows.

Using the ADO Extensions.

The ADO Dbase Class.

Database Access in VB.NET.

Using ADO.NET.

Connecting to a Database.

Reading Data from a Database Table.

Executing a Query.

Deleting the Contents of a Table.

Adding Rows to Database Tables Using ADO.NET.

Making the VB.NET ADO Facade.

The DBTable class.

Creating Classes for Each Table.

Storing the Prices.

Loading the Database Tables.

The Final Application.

What Constitutes the Facade?

Consequences of the Facade.

Programs on the CD-ROM.

20. The Flyweight Pattern.

Discussion.

Example Code.

The Class Diagram.

Selecting A Folder.

Writing a Flyweight Folder in VB.NET.

Flyweight Uses in VB.

Sharable Objects.

Copy-on-Write Objects.

Programs on the CD-ROM.

21. The Proxy Pattern.

Sample Code.

Writing a Proxy in VB.Net.

Proxies in VB.

Copy-on-Write.

Comparison with Related Patterns.

Programs on the CD-ROM.

Summary of Structural Patterns.

IV. BEHAVIORAL PATTERNS.

22. Chain of Responsibility.

Applicability.

Sample Code.

The List Boxes.

Programming a Help System.

Receiving the Help Command.

A Chain or a Tree?

Chain of Responsibility in VB.NET.

Kinds of Requests.

Examples in VB.

Consequences of the Chain of Responsibility.

Programs on the CD-ROM.

23. The Command Pattern.

Motivation.

Command Objects.

Building Command Objects.

Arrays of Commands.

Consequences of the Command Pattern.

Providing Undo.

The Command Pattern in VB.NET.

The CommandHolder Interface.

Handling Undo Commands in VB.NET.

The Command Pattern in the VB Language.

Programs on the CD-ROM.

24. The Interpreter Pattern.

Motivation.

Applicability.

A Simple Report Example.

Interpreting the Language.

Objects Used in Parsing.

Reducing the Parsed Stack.

Implementing the Interpreter Pattern.

The Syntax Tree.

Building an Interpreter in VB.

The Parse Objects.

Consequences of the Interpreter Pattern.

Programs on the CD-ROM.

25. The Iterator Pattern.

Motivation.

Sample VB6 Code.

Fetching an Iterator.

Filtered Iterators.

The Filtered Iterator.

Iterators in VB.NET.

Consequences of the Iterator Pattern.

Programs on the CD-ROM.

26. The Mediator Pattern.

An Example System.

Interactions between Controls.

Sample Code.

Initialization of the System.

Mediators and Command Objects.

The Mediator in VB.Net.

Initialization.

Handling the Events for the New Controls.

Consequences of the Mediator Pattern.

Single Interface Mediators.

Implementation Issues.

Programs on the CD-ROM.

27. The Memento Pattern.

Motivation.

Implementation.

Sample Code.

A Cautionary Note.

Command Objects in the User Interface.

Handling Mouse and Paint Events.

Writing a Memento in VB.NET.

Consequences of the Memento.

Programs on the CD-ROM.

28. The Observer Pattern.

Watching Colors Change.

Writing an Observer in VB.NET.

The Message to the Media.

Consequences of the Observer Pattern.

Programs on the CD-ROM.

29. The State Pattern.

Sample Code.

Switching Between States.

How the Mediator Interacts with the State Manager.

Handling the Fill State.

Handling the Undo List.

Filling Circles in VB.

A State Pattern in VB.NET.

Mediators and the God Class.

Consequences of the State Pattern.

State Transitions.

Programs on the CD-ROM.

30. The Strategy Pattern.

Motivation.

Sample Code.

The Context.

The Program Commands.

The Line and Bar Graph Strategies.

Drawing Plots in VB.

A Strategy Pattern in VB.NET.

Consequences of the Strategy Pattern.

Programs on the CD-ROM.

31. The Template Method Pattern.

Motivation.

Kinds of Methods in a Template Class.

Sample Code.

Drawing a Standard Triangle.

Drawing an Isosceles Triangle.

The Triangle Drawing Program.

Templates and Callbacks.

Summary and Consequences.

Programs on the CD-ROM.

32. The Visitor Pattern.

Motivation.

When to Use the Visitor Pattern.

Sample Code.

Visiting the Classes.

Visiting Several Classes.

Bosses are Employees Too.

Catch-All Operations with Visitors.

Double Dispatching.

Why Are We Doing This?

Traversing a Series of Classes.

Writing a Visitor in VB.

Consequences of the Visitor Pattern.

Programs on the CD-ROM.

Bibliography.
Index. 0201702657T11152001

Preface

This is a practical book that tells you how to write Visual Basic (VB6 and VB.NET) programs using some of the most common design patterns. It also serves as a quick introduction to programming in the new VB.NET version of the VB language. The pattern discussions are structured as a series of short chapters, each describing a design pattern and giving one or more complete working, visual-example programs that use that pattern. Each chapter also includes UML diagrams illustrating how the classes interact.

This book is not a "companion" book to the well-known Design Patterns text by the "Gang of Four." Instead, it is a tutorial for people who want to learn what design patterns are about and how to use them in their work. You do not have to have read Design Patterns to read this book, but when you are done here you may well want to read or reread it to gain additional insights.

In this book you will learn that design patterns are frequently used ways of organizing objects in your programs to make them easier to write and modify. You'll also see that by familiarizing yourself with them, you've gained some valuable vocabulary for discussing how your programs are constructed.

People come to appreciate design patterns in different ways--from the highly theoretical to the intensely practical--and when they finally see the great power of these patterns, an Aha! moment occurs. Usually this moment means that you suddenly have an internal picture of how that pattern can help you in your work.

In this book, we try to help you form that conceptual idea, or gestalt, by describing the pattern in as many ways as possible. The book is organized into six main sections: an introductory description, an introduction to VB.NET, and descriptions of patterns, grouped as creational, structural, and behavioral.

For each pattern, we start with a brief verbal description and then build simple example programs. Each of these examples is a visual program that you can run and examine to make the pattern as concrete a concept as possible. All of the example programs and their variations are on the companion CD-ROM, where you run them, change them, and see how the variations you create work.

We show that you can use design patterns effectively in VB6 and then show the same patterns in VB.NET (also called VB7). Since each of the examples consists of a number of VB files for each of the classes we use in that example, we also provide a VB project file for each example and place each example in a separate subdirectory to prevent any confusion. We place the VB.NET examples in a separate directory under each pattern. This book is based on the Beta-2 release of VB.Net. Any changes between this version and the final product will probably not be great. Consult the Addison-Wesley Web site for updates to any example code.

If you leaf through the book you'll see screen shots of the programs we developed to illustrate the design patterns, providing yet another way to reinforce your learning of these patterns. In addition, you'll see UML diagrams of these programs, illustrating the interactions between classes in yet another way. UML diagrams are just simple box-and-arrow illustrations of classes and their inheritance structure, where arrows point to parent classes, and dotted arrows point to interfaces. And if you're not yet familiar with UML, we provide a simple introduction in the secondchapter.

When you finish this book you'll be comfortable with the basics of design patterns and will be able to start using them in your day-to-day Visual Basic programming work.

James W. Cooper
Nantucket, MA
Wilton, CT
Maui, HI
October, 2001



0201702657P11152001

Index

A

a array, sorting elements, 61-62
Abstract class, 314
Abstract classes, 7-8
Factory Method pattern, 113
Abstract Factory pattern, 103, 180
adding classes, 136
GardenMaker Factory, 127-129
isolating concrete classes, 136
subclasses, 136
VB.NET GardenMaker program, 131-135
Abstract methods, 12
AbstractDecorator interface, 233
AbstractEmployee class, 213-214, 221-222
AbstractEmployee interface, 221, 224-225
AbstractExpression class, 347, 348
program, 136
Abstraction, 197
accept method, 448-453, 455-456, 458
Access, 244
AccessException exception, 94
Accessor functions, 41
ActionVerb class, 350
ActiveX Control command, 43
ActiveX controls
as bridges, 204
as decorators, 236
Adapter pattern, 181, 298
class adapters, 194-195
DataGrid control, 192-193
moving data between lists, 183-185
MSFlexGrid control, 185-187
pluggable adapters, 196
TreeView adapters, 191-192
TreeView control, 187-188
two-way adapters, 195
VB.NET usage, 189-190
Adapters, 183, 239
program, 196
add method, 92, 215, 223, 328
addArgsToVerb method, 351
addChain method, 306
AddItem method, 185
AAddNew method, 245, 259
addNode method, 220
Address object, 149
addText method, 186, 187, 191, 195
ADO (ActiveX Data Objects), 245
ADO databases
accessing in VB6, 256-264
adding columns to tables, 260
adding rows to tables, 259
ADOX (ADO extensions), 259-260
Connection object, 258-259
DBase class, 260-262
finding rows matching criteria, 259
Indexer class, 262-264
primary key, 260
table creation, 259-260
ADOCommand object, 265
ADO.NET
adding rows to tables, 267-268
connecting to database, 265
deleting table contents, 266
executing queries, 266
reading data from table, 265
ADOX (ADO extensions), 256, 259-260
afterSelect event, 226
Age property, 30
AgeSwimData class, 172, 174
All buttons class, 303-304
Ancillary classes, 57
Annotation and UML diagrams, 15-16
AnnualGarden class, 129, 133
AppendText method, 99
Applications, switching states, 403
Approach, 244
ArgumentException exception, 94
ArgumentNullException exception, 94
ArithmeticException exception, 94
ArrayList class, 156, 158, 175, 208, 272, 342
ArrayList object, 91
Arrays, 89-91
collection objects, 91-93
of commands, 322-325
dynamic, 90
error conditions, 93
Hashtables, 91-92
index out-of-range statements, 93
relocating space in, 90
resizing, 90-91
SortedList class, 92
specifying contents of, 90
strings, 75
variable-length objects, 91-93
variables, 90
zero-based, 89, 91, 175
ASPs (Active Server Pages), 298
Attributes method, 99
Autoincrement property, 260

B

BarPlot class, 437
BarPlotStrategy class, 429, 432
.bas file type, 68
Base class
defining all methods in, 136
methods, 55
BaseClass class, 83
Behavioral design patterns, 6
Behavioral patterns, 301
Bitmap class, 296
BlueCommand class, 336
blueCommand object, 328
Bond class, 52-54
duplicated code, 55
inserting an instance of Equity class inside, 56
Bonds class, 152, 153, 157
BonsaiGarden class, 136
Booch, Grady, 11
Boss class, 216-218, 221, 225, 451-453, 457-458
Bosses class, 213
BossVisitor class, 455
Bridge class, 201, 202, 208
Bridge pattern, 181, 197-200
Abstraction, 197
ActiveX controls as bridges, 204
changing data side, 208-209
class diagram, 201
ConcreteImplementors, 197
consequences of, 210
extending Bridge class, 202
Implementor, 197
ListBox class, 206
loading data, 207
ProductTable class, 206-207
program, 210
Refined Abstraction, 197
VB.NET, 205-207
visList interface, 200-201
Bridger class, 197-198, 199, 201
Bridger interface, 205
program, 210
btnRed button, 319
Builder class, 150, 151
Builder pattern, 103, 149-150, 180
calling builders, 152-154
Check Box Builder, 154-155
CheckChoice class, 158-159
consequences of, 162
Investment Tracker, 150-151
Items collection in ListBox control, 160-161
List Box Builder, 154
ListboxChoice class, 159-160
program, 162
StockFactory class, 157
VB.NET creation of, 156-160
Building objects, 38-39
Buttn class, 333
Button class, 331
Buttons
behavior, 404-405
command objects, 410
decorating, 229
explaining operations of, 303-304
bVacationVisitor class, 452, 453
ByRef modifier, 60
ByVal modifier, 60

C

C#, 66
Caching results, 227
calcLaneOrder function, 115
calcValue method, 56
Callbacks and templates, 444
Caretaker class, 384, 387, 394
Caretaker object, 382
Catalog object, 259
Catch statement, 93
Catch-all operations with visitors, 454-455
CDate function, 64
CDbl function, 63, 64
Celsius temperature scale, 17-20
Chain class, 306, 314, 351
Chain interface, 309, 310, 351
Chain of Responsibility, 301, 303-304
command-interpreter program, 304-307
consequences of, 317
Help system, 310-312
inheritance, 317
Interpreter pattern, 348-353
linearity, 313
list boxes, 308-309
program, 318
tree structure, 313-314
types of requests, 316
usage, 304
VB examples, 316-317
VB.NET, 314-316
Check Box Builder, 154-155, 158
Checkbox type, 158
CheckChoice class, 158-159
Child nodes, 187-188, 212
CInt function, 63, 64, 177
Circle class, 405
Circle object, 406
Circle seeding, 113, 120
CircleButton class, 420
CircleSeeding class, 115, 118, 120
Class adapters, 183, 194-195
VB.NET, 195-196
Class keyword, 68
Class modules, 19
Classes, 19, 27
adding and removing at run time, 179
adding to Abstract Factory pattern, 136
ancillary, 57
circular references to other classes, 179
cloning, 166, 168, 179
concrete, 129
constructors, 30, 74-76
containment, 29-30
data, 38
deep copy, 168
derived, 7-8
dissimilar with same interface, 172-174
encapsulating error handling, 24-25
format and value conversion, 22-25
functions, 40
global point of access, 140
handling requests, 303-304
hierarchy representation, 14-15
holding data, 20
implementing interface, 86
inheritance, 7-8, 12-14, 78
initializing, 30, 73
inside of classes, 15
instances, 19, 27, 38
instantiating, 38
methods, 38
names, 12, 38, 68
naming, 35-36
naming instances, 36
New methods, 73
as objects, 27-30
only one accessible instance, 138
patterns, 181
properties, 30-32
shallow copy, 168
sharable instances, 279
shared methods, 143-144
subclasses, 13
traversing series of, 456
variables, 40-41
VB.NET, 67-68
visiting, 451-453
Classes and interfaces, 32-33
Class_Initialize event, 30, 137
Clear method, 47, 92, 371
ClearButton class, 376, 420
Clearing text boxes, 47
click event, 410
Click method, 71
Client object, 347
CLng function, 64
Clone method, 166
Cloning, 166, 168, 179
closeTriangle method, 444
.cls file extension, 39, 68
clsTemp class, 19-22
clsTemp class module, 19
cMain module, 69
cmdButton class, 334
cmdButton control, 331
cmdMenu class, 333, 334
CmdToolBarButton class, 420
Cocoon factory, 111-112
Colleague interface, 378
Colleagues, 369
Collection objects, 28, 91-93
ColorChain class, 307
ColorForm window, 397
ColorImage class, 309
Column object, 260
comClick method, 142
ComdHolder class, 334-335
Command class, 50
Command interface, 49-50, 321, 324, 326, 330, 331, 376, 420
Command objects, 258, 320-321, 332, 347, 384, 421
building, 321-322
buttons, 410
containers for, 333
mediator pattern, 373
Undo function, 326-330
in user interface, 389-390
Command pattern, 301
arrays of commands, 322-325
building command objects, 321-322
command objects, 320-321
CommandHolder interface, 332-335
consequences of, 325
motivation for use of, 319
program, 338
providing Undo function, 326-330
UndoCommand version, 335-338
VB.NET, 330-332
CommandHandler, 376
CommandHolder interface, 332-335
Command-interpreter program, 304-307
Commands
arrays of, 322-325
program, 338
queuing, 321
undoing, 326-330
Comments and UML diagrams, 15-16
commForm control, 143
CommonDialog object, 322
Communication patterns, 5
Compilers and VB.NET options, 63
Compiling user controls, 47
Components, constructing objects from, 149
Composite pattern, 211-212
Boss class, 216-218
building employee tree, 219-221
caching results, 227
computing salaries, 213
consequences of, 222-223
doubly linked lists, 221-222
employee classes, 213-215
Enumerator, 225
implementation, 212-221
multiple boss constructors, 226
ordering components, 227
program, 228
self-promotion, 221
SimpleComposite example, 223
Subords class, 215-216
VB.NET, 223-226
Composites, 181, 211-212, 239
program, 228
Composition, 14-15
Computing salaries, 213
Concrete classes, 129, 136
Concrete Factory class, 129, 130
Concrete methods, 439
ConcreteImplementors, 197
Connection object, 258-259, 260
Console application, 69
Console.WriteLine statement, 62
Constructors, 30
filename and path, 99
hello window, 73
overloading, 77
private, 144
VB.NET, 74-76
Containers, 223
Command object and, 333
Containment, 43
contains method, 92, 386
Context class, 425, 427-428
Context interface, 435
Context object, 347
ControlAdapter class, 187
ControlAdapter interface, 188
Controller, 4
Controls, 72
adding methods, 187
creation of, 236
declared as variable, 72
derived from Windows control, 331
event handling, 376-377
focus, 311
initialization, 375-376
interactions between, 369-370
modifying code for, 72
naming, 35
repainting, 76
Tooltips, 76
Controls collection, 223
Convert class, 64
Converting
formats, 22-25
to Kelvin, 20-21
values, 22-25
CoolButtons class, 232-233
CoolDecorator class, 230-232
Copy method, 371
CopyButton class, 376
CopyCommand class, 370
Copy-on-Write objects, 290-291, 298
CopyTo method, 92
count method, 157
count property, 212
CreateText method, 97
Creational patterns, 6, 103-104
CSng function, 63, 64
CStr function, 64
Ctype function, 158
Currency type, 64
Current property, 77
currentState variable, 408
Cursor class, 296
Cursor object, 77
Cursors, 77

D

Data, 38
conversions, 177
displaying in multiple forms, 395-396
extracting from databases, 243-244
loading, 207
manipulation, 18
moving between lists, 183-185
public or private modifier, 38-39
valid, 41
Data model, 3-4
Data representations of trees, 211
Database object, 245
Databases, 165, 241-243
ADO (ActiveX Data Objects), 245
ADO access, 256-264
connection strategies, 245
DataTable class, 192
extracting data from, 243-244
indexes, 241
MDAC (Microsoft Data Access Components), 245
ODBC (Object Database Connectivity), 244-245
prototype usage, 166-170
RDO (Remote Data Objects), 245
Recordset, 166
relationships between tables, 250
structure, 245-248
tables, 242, 245, 250
types, 244
VB.NET access, 264
DataColumns class, 192
DataGrid class, 196
DataGrid control, 192-193, 206
DataRow object, 264
DataSet object, 264
DataTable class, 192, 193
DataTable object, 264, 267
db variable, 258
DB/2, 244
dBase, 244
DBase class, 246-248, 256, 260-262, 268, 290
DBTable class, 256, 269-270, 272
DBTable interface, 250, 253
Decimal type, 64
Decorating
buttons, 229
CoolButton, 230-232
PictureBox, 230
Decorator class, 230
Decorator pattern, 181, 229, 298
ActiveX controls as decorators, 236
consequences of, 239
decorating CoolButton, 230-232
decorator usage, 232-235
program, 240
VB.NET, 236-238
Decorators, 229, 239
ActiveX controls as, 236
usage, 232-235
Deep copy, 168
Default namespace, 78
Delete method, 99
Deleting files, 33, 96
Derived classes, 7-8, 78, 84, 229
calling methods from, 55-56
overriding, 81-82
overriding methods, 81-82
Simple Factory pattern, 106-107
Design Patterns, 4, 7
Design patterns, 3-4, 103
acceptance, 6
behavioral, 6
creational, 6
defining, 5-6
discovery of, 6
internalization, 7
learning process, 6-7
Model-View-Controller framework, 3-4
reason for using, 7
recognition, 6-7
structural, 6
studying, 7
VB6, 8
VB.NET, 8
Visual Basic, 8
(The) Design Patterns Smalltalk Companion, 4
Design Patterns—Elements of Reusable Software, 4
Dim statement, 61, 63-64
new keyword, 19
VB.NET, 60
Director class, 151
DirectoryNotFoundException exception, 94
DivideByZeroException exception, 94
Dividing strings into tokens, 25-27
Double dispatching, 455
DoubleRect class, 81, 82
Doubly linked lists, 221-222
Draw method, 282
overloading, 82
draw method, 132, 329, 392, 419, 441, 442, 444, 448
draw2Line method, 441, 442, 444
drawCommand class, 329
drawData objects, 328
drawHandle method, 417
Drawing, 76
plots, 429-432
VB.NET, 76-77
Drawing class, 416
Drawing interface, 414, 417
drawLine method, 444
drawList collection, 328
drawRectangle method, 286
Dynamic arrays, 90
Dynamically changing forms, 152

E

Edit method, 245
elements method, 362
Employee class, 12-15, 213-215, 218, 221, 223-225, 449, 453, 456-457
Employee interface, 457
Employees class, 213
employees Collection, 223
EmployeeVisitor class, 455
Encapsulating error handling, 24-25
Encapsulation, 7, 8, 41, 43, 81, 189
EndIf keyword, 60
EndOfStreamException exception, 94
Enumerator, 225
Equities class, 156, 157
Equities interface, 152
Equity class, 53, 160, 161
Equity interface, 53, 54, 153
Error handling in Singleton pattern, 145-146
ET++, 4
Event object, querying, 71
EventFactory factory, 121
Events
Factory Method pattern, 121
handling for controls, 376-377
Events class, 113-115, 117-119, 121-122
Examplar pattern, 165
Exception handling, 93
Exceptions, 93-94, 145-146
file handling, 97
file input and output, 97
multiple, 94-95
throwing, 95
.EXE file, 47
Execute method, 50, 320, 330, 333, 411, 420-421, 434
ExecuteNonQuery method, 266
Exists method, 99
exit class, 321
ExitCommand class, 50, 334
ExitCommand object, 50
ExitMenu class, 331-332
Extending Bridge class, 202
Extension method, 99
External iterators, 365
External static variables, 137
Extracting data from databases, 243-244

F

Facade classes, 249-252
Facade pattern, 181, 241
ADO.NET, 264-268
consequences of, 276
elements, 276
Facade classes, 249-252
Foods table, 252-253
price query, 255
Price table, 253-255
Stores class, 250-252
Stores table, 252-253
usage, 256
VB7-style grocery database, 268-275
Facade program, 277
FacadeADO program, 277
Factor variable, 40
Factories, 103
Factory class, 151
Factory Method pattern, 103, 113
abstract classes, 113
circle seeding, 120
events, 121
Events class, 117-119
straight seeding, 119-120
subclasses, 113
Swimmer class, 117
uses for, 123
VB7 seeding program, 121-123
viewing seedings, 120
Factory pattern, 180
math computation, 111-112
program, 112, 124
Fahrenheit temperature scale, 17-20
FFT (Fast Fourier Transform), 111
Field object, 245
File class, 96, 99, 144, 166
File handling, 33-35, 95-97
File method, 95
File object, 96-97
File|Add project command, 45
File.AppendText method, 96
FileChain class, 315
FileCommand class, 334
File.Copy method, 96
File.Delete method, 96
File.Exists method, 96
File|Exit command, 319, 321, 330
File.getAttributes method, 96
FileInfo class, 98-99
FileList class, 309
File|Make Project Group command, 47
File.Move method, 96
File|New Project command, 43, 69
File|New project command, 70
FileNotFoundException exception, 94
File|Open command, 319, 322, 330
File.OpenText method, 96
File.OpenWrite method, 96
File|Red command, 319
Files
checking for existence of, 33
deleting, 33, 96
information about, 98-99, 144
input and output and exceptions, 97
manipulation code and try blocks, 97
opening, 33
program, 101
reading data from, 33
renaming, 33
FileStream object, 96
Fill class, 405, 407
fill method, 420
Fill State object, 412-413
FillButton class, 420
FillDataSet method, 265
FillMemento class, 415
Filtering iterators, 360-362
FinalImage class, 295, 296
First normal form (1NF), 242
FirstFirst class, 110
Float constant, 290
Flyweight classes, 282
Flyweight pattern, 181, 279-280
class diagram, 284
copy-on-write objects, 290-291
example code, 280-286
selecting folder, 284-286
sharable objects, 290
uses in VB, 290
VB.NET, 286-289
FlyweightFactory class, 280
program, 291
FNamer class, 106-107
Folder class, 286
FolderFactory class, 281-282, 283, 286
Folders
icons for, 280-286
selecting, 284-286
Food class, 270
Food table, 274
FoodKey, 250
FoodName, 250
Foods table, 250, 252-253, 272
Form class, 72
Form1.vb form project, 70
Format method, 63, 226
Formats, converting, 22-25
Form_Load event, 25, 121, 187, 233-234, 308, 371
Forms
control creation, 236
controls, 72
displaying data in multiple, 395-396
dynamically changing, 152
name order, 106
simple, 71
Form_Unload event, 321
FoxBase, 244
Friend classes, 86
friend keyword, 382, 391
.frm file extension, 39, 68
Functional libraries, 67
Functions, 40, 61
Funds class, 152

G

Gamma, Erich, 4
Gang of Four, 4
Garbage collection, 66-67
Garden class, 127, 131, 132
Garden interface, 128
Garden objects, 129
Gardener class, 134
GardenMaker Factory, 127-129, 130-131
GardenMaker window class, 133
Get functions, 40
Get method, 20, 65
Get property, 31
getAge method, 30, 167
getAvailablePorts method, 142
getBorder method, 132
getCels method, 20
getCenter method, 132
getChain method, 306
getChild method, 212, 215, 220, 223
getClass method, 106
getFahr method, 20
getFormatted accessor function, 23
getIterator method, 359
getJob method, 13-14
getKelvin function, 21
getLaneOrder function, 123
getName method, 167
getNames method, 157
getSalaries method, 213, 218, 225
getSeconds accessor function, 23
getSeeding method, 115, 117, 123
getSelected method, 154, 155
getShade method, 132
getSingle accessor function, 23
getSpooler method, 138, 145-146, 147
getSwimmer method, 167
getSwimmers method, 120
getTaxable method, 54
getTime method, 167
getVacDays function, 450
getValidPorts method, 142
getValue method, 213, 272
getWindow interface, 151
getXXX accessor functions, 28-29
GoF book, 4
GotFocus event, 45
Graphics, 76-77
Graphics object, 286, 392
GrassGarden class, 136
Grid adapter, 195
GridAdapter class, 192, 206
Groceries database, 264

H

Hashtables, 270, 392-393
count property, 92
Enumerator property, 271
key value, 91-92
hasMoreElements method, 216, 358, 361
Height method, 136
Hello window constructors, 73
Help (F1) key, 310
Help system, 303-304
Chain of Responsibility, 310-312
Hidden interfaces, 57
Highlighted text fields, 43-45
HiText User Control, 45-46
HiTextBox.vb object, 84
Hook methods, 439
HtextBox control, 85, 86
Hungarian notation, 35

I

Icon class, 296
IEnumerable interface, 225, 364
IEnumerator interface, 223, 225, 364
Image control, 294, 306
Image proxy, 294
ImageProxy class, 294, 297
Imager class, 309
Imager interface, 296
Imager object, 294
ImgChain class, 306
Implementor, 197
Imports statement, 67
Indexer class, 247, 256, 262-264
Indexes collection, 260
Indexes for databases, 241
indexOf method, 60-61, 92
IndexOutOfRangeException exception, 94
Indicators for using interfaces, 52-55
Inheritance, 7-8, 12-14, 41-42, 183
adding responsibilities with, 239
Chain of Responsibility, 317
classes, 78
program, 57
Simple Factory pattern, 109
VB.NET, 72-74, 78
Init method, 30, 50, 51, 74-75, 79-80
init method, 54, 207, 370, 373, 376, 386
In-memory data array, 192
Insert method, 92
Instances, 19, 27
intrinsic data, 279
naming, 36
TapeMeasure class, 38, 39
Instantiating classes, 38
Instr function, 26, 60-61
Integer constant, 290
Integers, 387
Interactions
between controls, 369-370
between objects, 5
Interator pattern
fetching iterator, 359-360
sample VB6 code, 358-360
Interfaces, 7-8, 14, 49-50
classes and, 32-33
converting into another interface, 183
definition, 49
deriving base, 136
dissimilar classes with same, 172-174
hidden, 57
implementing, 49
implementing methods, 86
indicators for using, 52-55
inheritance, 183
Iterator, 357
looking the same as class’s interface, 197
manipulation, 18
object composition, 183
public, 86
varying without changing implementation, 202
VB.NET, 85-86
Voltmeter program, 32-33
Internal iterators, 365
InterpChain class, 348, 350, 351
Interpreter pattern, 301, 339
Chain of Responsibility, 348-353
consequences, 354-355
flexibility, 347
implementing, 347-350
interpreting language, 341-342
motivation for using, 339
objects in parsing, 342-346
parsing objects, 353-354
reducing parsed stack, 346-347
report generator, 340-341
syntax tree, 348-350
VB6, 350-353
Interpreters, 339-340
Interpreting language, 341-342
Invalid port number error, 141, 142
Invest method, 51
Investment simulator, 50-52
Investment Tracker, 150-154
isBond method, 54
isCelsius Boolean, 22
IsNull method, 98
isUndo method, 328
Item method, 92
Items collection, 160-161, 189
Iterator interface, 358
Iterator pattern, 301
data modification, 364-365
external versus internal iterators, 365
filtering iterators, 360-362
motivation, 357-358
priviledged access, 365
program, 365
VB.NET, 363-364
Iterators, 357
fetching, 359-360
filtering, 360-362

J

j variable, 62
Jacobson, Ivar, 11
Java Design Patterns Java: A Tutorial, 4

K

Kelvin, converting to, 20-21
Key value, 91-92
Keyboard listeners, 311
KeyDown event, 311-312
kid variable, 361
kidClub class, 362
KidClubIterator class, 361, 363
KidData class, 358, 360, 361, 362
KidIterator class, 359, 364
KidList class, 360
KidListBox class, 376
Kids class, 359, 376
Kids object, 323

L

LastFirst class, 110
lastMeasure method, 41
lbHi label, 71
Leaf node, 212
Leaves, 211-212
Left function, 60-61
legalInstance variable, 138
Length method, 98-99
Let method, 65
Let property, 31
Line command, 430
Line Input statement, 95
LineCmd class, 428-429
LinePlot class, 437
LinePlotStrategy class, 429, 432
List adapter, 195
List Box Builder, 154
List boxes and Chain of Responsibility, 308-309
ListAdapter class, 189, 190
ListBox class, 188, 189, 194, 197, 200, 206, 308
ListBox control, 160-161
ListboxChoice class, 159-160
listBridge class, 199, 200, 201, 205
listener, 337
ListIndex property, 189
Lists, moving data between, 183-185
LNamer class, 107
Loading data, 207

M

Macro language recorders, 339
Main module, renaming, 69
MainMenu control, 331
makeBoss method, 226
makeCel method, 22
makeFahr method, 22
Managed languages, 66
Manager class, 454-455
ManagerVisitor class, 455
Math computation in Factory patterns, 111-112
MDAC (Microsoft Data Access Components), 245
MDAC package, 257
MDI forms, dynamically changing, 152
Measure.cls program, 38
Measure.frm classes, 38
Measurement program, 39-40
Measurer form, 40
Mediator class, 370, 386, 420
Mediator pattern, 301, 367
Colleagues, 369
command objects, 373
consequences, 377-378
example system, 367-368
handing events for controls, 376-377
implementation issues, 378
initialization, 375-376
initialization of system, 372-373
interactions between controls, 369-370
sample code, 370-373
VB.Net, 373-377
Mediators
god class and, 421-422
interacting with state manager, 409-411
single-interface, 378
Memento class, 386, 394, 416, 420
Memento interface, 413-414
Memento object, 382, 387, 413
Memento pattern, 301, 381
checking type of object, 389
command objects in user interface, 389-390
consequences, 394
handling mouse and paint events, 390-391
implementation, 382
motivation, 381-382
sample code, 382-389
VB.NET, 391-393
MenuItem class, 331, 333
MessageBox class, 144
Metafile class, 296
Methods, 12, 19, 37, 38, 40
adding to controls, 187
base class, 55
calling arguments, 77
concrete, 439
File class, 96
Hook, 439
inaccessible overloaded, 83
MustOverride, 439
nonshared, 144
overloading, 78
overriding in derived classes, 81-82
polymorphic, 77
private, 22, 38-39, 40, 81
protected, 81
public, 22, 38-39, 40, 81
registering as event handler, 332
reusing, 55-57
shared, 96
signatures, 77
static, 96
template, 439
types in Template class, 439
vbFile class, 34
minVal value, 25
mnuExit menu item, 319
mnuOpen menu item, 319
mnuRed menu item, 319
Model-View-Controller framework, 3-4
Module module, 68
Modules, 68-69
Mouse events, handling, 390-391
mouse move event handler, 288
MouseDown method, 417
MouseLeft event, 231
MouseMove event, 231, 316
mouse_over flag, 237
mouseUp event, 405
move method, 417
Moving data between lists, 183-185
MSComctlLib.Button class, 389
MSComm control as Singleton pattern, 140-143
MSFlexGrid control, 185-187, 197
MultiChoice factory, 161
MultiChoice interface, 156
multiChoice interface, 151
multiChoice windows, 152
Multiple boss constructors, 226
Multiple exceptions, 94-95
multiselect list box, 159-160
MultVar class, 346, 349
MustInherit keyword, 176, 314
MustOverride keyword, 13, 176, 314, 439
Mutuals class, 152, 153, 157
MyBase.New method, 74

N

Name method, 99
NameClass class, 109-110
Namer class, 109
Namespaces, 67-68
VB.NET, 78-80
.NET applications, 59
New constructor, 74, 144
New dialog box, 70
New keyword, 19
New method, 74, 178, 207
New methods, 78
nextElement method, 216, 361
Next-Token method, 26
nextTop method, 342
NoCmd class, 308
Node class, 223
Nodes, 211-212
Nodes collection, 187
Nonleaf node, 212
Nonshared methods, 144
NonTerminalExpression object, 347, 350
Nonvisual decorators, 239
Normal form, 242-243
Null Reference exception, 98
Null strings and length method, 98
NullReferenceException exception, 94
Numbers, 63-64

O

Object adapters, 183, 195
TreeView control, 188
VB.NET, 195-196
Object composition, 8, 183, 189
Object patterns, 181
Object type, 158
Object-oriented approaches, 7-8
Object-oriented code, reusing, 3
Object-oriented programming, 39-40
Object-oriented terminology, 41-42
Objects
building, 38-39
checking type, 389
classes as, 27-30
communicating, 4
constructing from components, 149
contained within other objects, 14-15
design, 5
forwarding request to specific, 319
inheritance, 41-42
instances, 38, 39, 103
interaction between, 5
methods, 37, 40
modifying behavior, 229
most suitable for action, 304
new at run time, 179
parsing, 342-346, 353-354
postponing creation, 293
represented as class modules, 38
representing relationships, 16
states, 38
storing state, 381-382
VB.NET, 63
Observer interface, 396, 399
Observer pattern, 301, 395-396
consequences, 401-402
notifying observers, 401
VB.NET, 399-400
watching colors change, 396-399
.OCX file, 47
ODBC (Object Database Connectivity), 244-245
OleDbCommand object, 264, 266
OleDbConnection object, 264
OleDbDataAdapter object, 264
OneSexSwimData class, 170-173
OnPaint event, 76, 79, 131, 236
OnPaint method, 80, 133
OpenMenu class, 331
OpenText method, 99
OpenWrite method, 99
Option Explicit directive, 63
Option Strict On statement, 63
Options dialog box, 139
Oracle, 244
Ordering components, 227
Originator class, 394
Originator object, 382
OurList class, 194
Output, varying kinds, 340
Overloading
constructors, 77
draw method, 82
methods, 78
setData methods, 83
shadowing, 83-84
OverLoads keyword, 77, 78
Overloads keyword, 224
Overriding
methods in derived classes, 81-82
onPaint event, 79
Windows controls, 84-85

P

Package name, 12
paint event, 390-391, 430
paint event handler, 287, 337
paint method, 133-134, 238, 433, 443
PaintEventArgs object, 76
Panel class, 156, 159, 161, 236
Paradox, 244
Parent node, 188
ParseObject class, 343, 353, 354
ParseObject interface, 353
Parser class, 344, 347, 350
ParseVar class, 343, 345, 353, 354
ParseVerb class, 343, 345, 353, 354
Parsing
algebraic strings, 340
objects, 342-346, 353-354
user commands, 340
Part-whole hierarchies, 211
Passing arguments by reference and value, 41
Pattern mining, 6
Peek method, 98
Pen object, 76
PerennialGarden class, 129
Person class, 11-15
Pick class, 405
PickButton class, 420
PickKids class, 324, 325
PictureBox control, 133-134, 433
decorating, 230
Image property, 296
PixtureBox, 232
Plant class, 131
Plant objects, 128, 129
plot method, 427, 430, 439
PlotPanel class, 439
PlotStrategy class, 426, 432
pluggable adapters, 196
Polymorphic methods, 77
Polymorphism, 41
pop method, 342
Port already open error, 141, 142
Prelim class, 122
PrelimEvent class, 114-115, 118, 120-121, 123
Price class, 250, 253, 255, 274
Price table, 250, 253-255, 274
PriceKey, 250
Prices class, 270, 272-273
Primitive elements, 212
Print class, 353
Print method, 144
Print object, 343
Printit class, 354
PrintSpooler class, 137
Private constructors, 144
Private methods, 22, 81
Private variables, 20, 81
Procedural programs, 39
Product class, 198
productList class, 201
ProductTable class, 200, 201, 206-207
Program objects, 320-321
Programming
object-oriented, 39-40
styles, 35-36
Programs
data manipulation, 18
interface manipulation, 18
procedural, 39
temperature conversion, 17-18
undo function, 326-330
Project|Add class module menu item, 19
Project|Add User Control command, 236
Project|Add User Control menu, 84
Project|Components command, 47
Project|References command, 257
Properties, 30-32
Properties command, 69
Properties window, 19
Property Get method, 30
Property Let method, 30
Property pages dialog, 67
PropertyChanged method, 47
Protected keyword, 81
Protected methods and variables, 81
Prototype class, 168
Prototype managers, 174-175
Prototype pattern, 104, 165, 180
additional methods in subclasses, 171-172
consequences of, 179
dissimilar classes with same interface, 172-174
prototype managers, 174-175
prototype usage, 166-170
usage, 170-174
VB7 creation of, 175-179
Prototypes, 165-170
Proxy pattern, 181, 293
comparing to related patterns, 298
Copy-on-Write, 298
sample code, 294-295
VB6, 298
VB.Net, 296-297
Public
interfaces, 86
methods, 22, 81
push method, 342

Q

Querying objects, 71
Queue object, 93
Queuing commands, 321
QuickImage class, 295, 296

R

RDO (Remote Data Objects), 245
Reading text files, 96, 99-100
Recordset object, 166, 245, 258, 259
Rect class, 405
Rectangle button, 382
Rectangle class, 78-80, 81, 284, 288, 386
Rectangle object, 392, 406
RectButton class, 390, 392, 420
RectState class, 417
RectState object, 406
RedButton class, 330-331
redButton class, 334
RedCommand class, 334
RedCommand object, 322
redCommand object, 328
ReDecorator class, 233-235
ReDim statement, 90-91
Reducing parsed stack, 346-347
Refined Abstraction, 197
Refresh method, 134
register method, 374
registerInterest method, 396
Remove method, 92
remove method, 215, 223
RemoveAt method, 92
Renaming
files, 33
Main module, 69
repaint method, 439
Repainting controls, 76
Repeating patterns, 5
Resize event, 45
Resizing
arrays, 90-91
Hitext User Control, 46
user controls, 45
RestList class, 309
restore method, 386, 388, 415
Reusing method, 55-57
Reusing object-oriented code, 3
Right function, 60-61
Rumbaugh, James, 11
Run (F5) keyboard shortcut, 69, 70

S

SayHello button and WithEvents modifier, 74
SayHello_Click subroutine, 74
Screen, updating, 131
Scripting.FileSystemObject object, 33
Second normal form (2NF), 242
Seeding class, 114-115, 121, 123
Select method, 371
SelectedIndex property, 189
selectOne method, 407
Sender class, 309
Sender object, 71
sendNotify method, 398, 399
sendToChain method, 306, 310, 315
Serial ports
access to, 140-143
listing available, 141, 142-143
status, 142
Set functions, 40
Set keyword, 19, 60
Set methods, 20
setAge method, 30
setBounds method, 429
setCels method, 20
setData method, 83-84
setFahr method, 20
setFill method, 417
setKelvin method, 21
setSelected method, 417
setSex method, 171-173
setSingle accessor function, 23
setText accessor function, 23
setUnits accessor function, 41
setXXX methods, 30
SexFrame class, 172
SexSwimData class, 170, 174
Shadowing and overloading, 83-84
Shadows keyword, 83, 84
Shallow copy, 168
Sharable objects, 290
Shared method, 96, 144, 157
Shared methods, 96, 143-144
Shared variables, 144
Shorthand equals syntax, 66
Signatures, 77
Simonyi, Charles, 35
Simple Factory pattern, 103
abstraction returning class, 109
building, 108-109
derived classes, 106-107
inheritance, 109
operation of, 105-106
sample code, 106
usage, 108-109
writing in VB.NET, 109-110
Simple forms, 71
Simple temperature conversion program, 17-18
SimpleComposite example, 223
Simplest window program, 70-72
Single-interface mediators, 378
Singleton classes, 140
Singleton pattern, 104, 137, 180
allowing small number of instances, 148
catching errors, 139
error handling, 145-146
global point of access, 140, 147
MSComm control as, 140-143
private constructors, 144
serial ports, 140
SpoolDemo program, 146
static method creation of, 137-139
VB.NET creation of, 143-146
Smalltalk and Model-View-Controller framework, 3-4
Smalltalk Companion, 4, 7
SolidBrush objects, 433
Solution Explorer window, 69
Sort class, 353, 354
sort function, 115, 123
Sort method, 92
sort method, 176, 178
Sort object, 343
sortBridge class, 202
SortedList class, 92
Sorting array a elements, 61-62
Split method, 25, 26, 75
spool_counter variable, 137
SpoolDemo program, 146
Spooler, 144
Spooler class, 144, 145
SpoolerException class, 145
SQL (Structured Query Language), 244, 266
SQL Server, 244
Square class, 79-80
Square from rectangle, 79-80
Stack class, 342
Stack object, 93
Startup module, 69
State class, 416-417
State interface, 407
State object, 405, 406
State pattern, 301, 403
consequences of, 422
Fill State object, 412-413
filling circles in VB6, 416
mediator interacting with state manager, 409-411
sample code, 403-408
state transitions, 422
switching between states, 408-409
undo list, 413-416
VB.NET, 416-421
StateManager class, 405, 408, 409, 420
States, 38
program, 423
switching between, 408-409
transitions, 422
Static methods, 12, 96, 137-139, 144
stdTriangle class, 441
Stock class, 52, 53-56
StockFactory class, 157
Stocks class, 152, 156
Store class, 270
Store table, 271, 274
StoreFoodPrice object, 272
StoreKey, 250
StoreName, 250
Stores class, 250-252
Stores table, 250, 252-253
Straight seeding, 113, 119-120
StraightSeeding class, 119, 120, 122-123
StraightSeeding subclass, 115
Strategy pattern, 301, 425
consequences of, 435
Context class, 427-428
drawing plots, 429-432
line and bar graph strategies, 429
motivation, 425-426
program commands, 428-429
sample code, 426-427
VB.NET, 432-435
Stream method, 95
Stream object, 98
StreamReader object, 96-97
StreamWriter object, 97
String class, 60, 75
String collection, 154
String constant, 290
String Tokenizer method, 77
Strings
arrays, 75
converting to numerical values, 63
dividing into tokens, 25-27
zero-based indexes, 61
StringTokenizer class, 73, 342, 344
strSd.seed method, 120
Structural patterns, 6, 181
Sub Main subroutine, 68
Subclasses, 13
Abstract Factory pattern, 136
additional methods in, 171-172
Factory Method pattern, 113
Subject interface, 396, 399
subordinates collection, 216
subordinates method, 215
Subords class, 215-216, 357
Subords collection, 217
Subroutines, arguments passed by value, 59-60
Substring method, 60-61
SwimData class, 167, 170, 172, 174, 175-176
SwimData interface, 171
Swimmer class, 28, 31, 117, 166, 167, 177
Swimmer object, 184, 190
Swimmer objects, 174
Swimmers class, 120
SwimmerTimes program, 31-32
Switching between states, 408-409
Sybase, 244
System namespace, 68
System.Drawing namespace, 78

T

Table object, 259
Tabledef object, 245
Tables, 242, 245, 250
first normal form (1NF), 242
normal form, 242-243
relationships between, 250
second normal form (2NF), 242
third normal form (3NF), 243
Tables collection, 260
TapeMeasure class, 38-41
tCallback method, 297
Temp variable
Temperature class, 19-22
Temperature conversion program, 17-18
Temperature variable, 20
Template class, 439
Template Method class, 439
Template Method pattern, 301, 437
consequences, 445
drawing isoseles triangle, 441-443
drawing standard triangle, 441
motivation, 437-439
sample code, 439-443
templates and callbacks, 444
triangle drawing program, 443
Template methods, 439
Templates, 437, 444
TerminalExpression object, 347, 350
Testing
for end of text files, 98
HiText User Control, 45-46
Text boxes, clearing, 47
Text fields, 43-45
Text files
opening, 97
reading, 96, 99-100
testing for end of, 98
writing, 97, 99-100
TextBox class, 43
Textbox class, 84
TextBox control, 85
Textbox control, 84
Third normal form (3NF), 243
Throw statement, 95
Throwing exceptions, 95
TimedFinal class, 122
TimedFinalEvent class, 114-115, 118, 120-122
TimerCallback class, 297
Times class, 29
TimeSwimData class, 174, 178
ToggleButton class, 382
Tokenizer class, 25-27, 30
ToolBarButton class, 420
Tools|Options command, 139
Tooltips, 76
top method, 342
toString method, 156, 160
Tree adapter, 195
TreeAdapter class, 187, 191-192
TreeNode class, 191
TreeNode collection, 191
TreeView adapters and VB.NET, 191-192
TreeView class, 191-192, 220, 223
TreeView control, 187-188
Triangle class, 439, 440-442, 444
TriangleForm class, 443
Try blocks, 93, 266
file manipulation code, 97
multiple exceptions, 94-95
Two-way adapters, 195
txEntry text box, 45

U

UML (Unified Modeling Language), 11
UML diagrams
abstract methods, 12
annotation, 15-16
basic, 11-12
class name, 12
comments, 15-16
composition, 14-15
inheritance, 12-14
interfaces, 14
methods, 12
package name, 12
representing object relationships, 16
static methods, 12
variables, 12
Undo button, 383
Undo command object, 237
Undo method, 388
unDo method, 328
UndoButton class, 392, 420
undoCommand object, 328
Undoing commands, 326-330
Unreasonable values, 24-25
Update method, 245, 259
Updating screen, 131
User controld
naming, 45
User controls, 43-45
adding properties and methods, 47
compiling, 47
resizing, 45
User errors, 139
User interfaces, 368
command objects, 389-390
controller, 4
data model, 3-4
GardenMaker Factory, 130-131
objects, 320-321
view, 4
UserControl canvas, 44
UserControl class, 84, 236, 331, 335-336
User-created namespaces, 78

V

VacationVisitor class, 453, 456
Val function, 20, 177
Value keyword, 65
Values
converting, 22-25
unreasonable, 24-25
VAR type, 343
Variables, 12, 38, 40-41
arrays, 90
assigning value, 61
declaring, 61-62, 78
external static, 137
initializing, 73, 78
length property, 90
passing arguments by reference and value, 41
private, 20, 40, 81
protected, 81
scope, 61-62
values of, 40
VB.NET, 76
Variant keyword, 60
Vars class, 346
VarVarParse class, 349, 352
VB6, 16
class name, 68
cloning, 166
design patterns, 8
properties, 65
visual builder (IDE) environment, 43
VB7. See VB.NET
VB7 GardenMaker program
PictureBox class, 133-134
RadioButton and Button events, 134
VB7-style grocery database, 268-275
classes for tables, 270-272
final application, 275
loading database tables, 274-275
storing prices, 272-273
VBA (Visual Basic for Applications), 339
vbFile class, 33-35, 99-100, 166, 177, 376
vbFile interface, 99
VB.NET, 16, 59, 66
arguments passed by value, 59-60
building applications, 69-70
calls to subroutines and methods, 59
class name, 68
classes, 67-68
compiler options, 63-64
constructors, 74-76
default project name, 70
design patterns, 8
Dim statement, 60
drawing, 76-77
graphics, 76-77
inheritance, 72-74, 78
interfaces, 88-86
namespaces, 78-88
numbers, 64
objects, 63
overloading, 77-78
properties, 65
returning value from function, 61
shorthand equals syntax, 66
simplest window program, 70-72
syntax differences, 59-61
TreeView adapters, 191-192
variable declarations and scoping, 61-62
variables, 76
VB.NET compiler, 64
vbObjectError constant, 139
VBPatterns namespace, 288
Verb class, 353
VERB type, 343
View, 4
visCircle class, 417, 419, 420
visit method, 448, 450-455
Visiting classes, 451-453
Visitor class, 448, 450, 452, 456
Visitor interface, 456
Visitor pattern, 301, 447
catch-all operations with visitors, 454-455
consequences, 459
double dispatching, 455
Employee and Boss visits, 453-454
motivation, 447-449
sample code, 449-451
traversing series of classes, 456
visiting classes, 451-453
writing visitor, 456-459
visList interface, 200-201, 205, 206
VisList object, 206
visRectangle class, 384, 386, 387, 391, 392, 417
Vistor class, 454
Visual Basic
case insensitivity, 35
design patterns, 8
programming styles, 35-36
project files, 16
Visual objects, overriding properties, 72
Visual Studio.NET, 69
Voltmeter program, 32-33

W

WateringFrequency method, 136
WebClass objects, 298
Wend keyword, 60
WildFlower class, 136
Windows Application, 70
Windows application buttons, 230
Windows controls, overriding, 84-85
Windows Designer, 70, 71
WindowsApplication1 application, 70
WithClass program, 16
WithEvents modifier, 74
Works, 244
Writing text files, 97, 99-100

X

X class, 106
XFactory class, 106
XY class, 106
XZ class, 106

Z

Zero-based arrays, 89, 91, 175

Updates

Submit Errata

More Information

ONE MONTH ACCESS!

WITH PURCHASE


Get unlimited 30-day access to thousands of Books & Training Videos about technology, professional development and digital media If you continue your subscription after your 30-day trial, you can receive 30% off a monthly subscription to the Safari Library for up to 12 months.