Visual Basic Design Patterns: VB 6.0 and VB.NET

Book description

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

    Table of contents

    1. Copyright
    2. PREFACE
    3. ACKNOWLEDGMENTS
    4. 1. Object-Oriented Programming in VB
      1. 1. What Are Design Patterns?
        1. Defining Design Patterns
        2. The Learning Process
        3. Studying Design Patterns
        4. Notes on Object-Oriented Approaches
        5. VB Design Patterns
        6. How This Book Is Organized
      2. 2. UML Diagrams
        1. Inheritance
        2. Interfaces
        3. Composition
        4. Annotation
        5. WithClass UML Diagrams
        6. Visual Basic Project Files
      3. 3. Using Classes and Objects in VB
        1. A Simple Temperature Conversion Program
        2. Building a Temperature Class
          1. Converting to Kelvin
        3. Putting the Decisions into the Temperature Class
        4. Using Classes for Format and Value Conversion
          1. Handling Unreasonable Values
        5. A String Tokenizer Class
        6. Classes as Objects
          1. Class Containment
        7. Class Initialization
        8. Classes and Properties
        9. Another Interface Example—The Voltmeter
        10. A vbFile Class
        11. Programming Style in Visual Basic
        12. Summary
      4. 4. Object-Oriented Programming
        1. Building VB Objects
        2. Creating Instances of Objects
        3. A VB Measurement Program
        4. Methods Inside Objects
        5. Variables
        6. Passing Arguments by Reference and by Value
        7. Object-Oriented Jargon
      5. 5. Building Your Own VB Control
        1. A Highlighted Text Field
          1. Resizing a User Control
        2. Testing Your HiText Controls
        3. Adding Properties and Methods to User Controls
        4. Compiling a User Control
        5. Summary
        6. Programs on the CD-ROM
      6. 6. Inheritance and Interfaces
        1. Interfaces
        2. An Investment Simulator
        3. Writing the Simulator
        4. Indicators for Using an Interface
        5. Reusing Common Methods
        6. Hidden Interfaces
        7. Summary
        8. Programs on the CD-ROM
      7. 7. Introduction to VB.NET
        1. Syntax Differences in VB.NET
          1. Improved Function Syntax
        2. Variable Declarations and Scoping
          1. Objects in VB.NET
        3. Compiler Options
          1. Numbers in VB.NET
        4. Properties in VB6 and VB.NET
        5. Shorthand Equals Syntax
        6. Managed Languages and Garbage Collection
        7. Classes in VB.NET
        8. Building a VB7 Application
        9. The Simplest Window Program in VB.NET
        10. Inheritance
        11. Constructors
        12. Drawing and Graphics in VB.NET
        13. Tooltips and Cursors
        14. Overloading
        15. Inheritance
        16. Namespaces
          1. Creating a Square from a Rectangle
        17. Public, Private, and Protected
        18. Overriding Methods in Derived Classes
        19. Overloading and Shadowing
        20. Overriding Windows Controls
        21. Interfaces
        22. Summary
        23. Programs on the CD-ROM
      8. 8. Arrays, Files, and Exceptions in VB.Net
        1. Arrays
        2. Collection Objects
          1. ArrayLists
          2. Hashtables
          3. SortedLists
        3. Exceptions
        4. Multiple Exceptions
        5. Throwing Exceptions
        6. File Handling
          1. The File Object
          2. Reading a Text File
          3. Writing a Text File
        7. Exceptions in File Handling
        8. Testing for End of File
        9. The FileInfo Class
        10. A vbFile Class
        11. Programs on the CD-ROM
    5. 2. Creational Patterns
      1. 9. The Simple Factory Pattern
        1. How a Simple Factory Works
        2. Sample Code
        3. The Two Derived Classes
        4. Building the Simple Factory
          1. Using the Factory
        5. Writing the Factory Pattern in VB.NET
        6. Factory Patterns in Math Computation
        7. Programs on the CD-ROM
      2. 10. The Factory Method
        1. The Swimmer Class
        2. The Events Classes
        3. Straight Seeding
          1. Circle Seeding
        4. Our Seeding Program
        5. Other Factories
        6. The Seeding Program in VB7
        7. When to Use a Factory Method
        8. Programs on the CD-ROM
      3. 11. The Abstract Factory Pattern
        1. A GardenMaker Factory
        2. How the User Interface Works
        3. Creating an Abstract Factory Using VB7
          1. The PictureBox
          2. Handling the RadioButton and Button Events
        4. Adding More Classes
        5. Consequences of Abstract Factory
        6. Programs on the CD-ROM
      4. 12. The Singleton Pattern
        1. Creating Singleton Using a Static Method
        2. Catching the Error
        3. Providing a Global Point of Access to a Singleton
        4. The MSComm Control as a Singleton
          1. Available Ports
        5. Writing a Singleton in VB.NET
          1. Using a Private Constructor
          2. Error Handling in Our Singleton
        6. A VB.NET SpoolDemo Program
        7. The Global Point of Access
        8. Other Consequences of the Singleton Pattern
        9. Programs on the CD-ROM
      5. 13. The Builder Pattern
        1. An Investment Tracker
        2. Calling the Builders
        3. The List Box Builder
        4. The Check Box Builder
        5. Writing a Builder in VB.NET
          1. The Stock Factory
          2. The CheckChoice Class
          3. The ListboxChoice Class
        6. Using the Items Collection in the ListBox Control
          1. The Final Choice
        7. Consequences of the Builder Pattern
        8. Programs on the CD-ROM
      6. 14. The Prototype Pattern
        1. Cloning in Visual Basic 6
        2. Using the Prototype
        3. Using the Prototype Pattern
          1. Additional Methods in Subclasses
          2. Dissimilar Classes with the Same Interface
        4. Prototype Managers
        5. Writing a Prototype in VB7
        6. Consequences of the Prototype Pattern
        7. Programs on the CD-ROM
        8. Summary of Creational Patterns
    6. 3. Structural Patterns
      1. 15. The Adapter Pattern
        1. Moving Data between Lists
        2. Using the MSFlexGrid
        3. Using a TreeView
          1. The Object Adapter
        4. Using Adapters in VB7
        5. TreeView Adapters for VB.NET
        6. Adapting a DataGrid
        7. The Class Adapter
        8. Two-Way Adapters
        9. Object versus Class Adapters in VB.NET
        10. Pluggable Adapters
        11. Adapters in VB
        12. Programs on the CD-ROM
      2. 16. The Bridge Pattern
        1. The visList Classes
        2. The Class Diagram
        3. Extending the Bridge
        4. ActiveX Controls as Bridges
        5. The Bridge Pattern in VB.NET
          1. The ListBox VisList Class
          2. The Grid VisList Class
          3. Loading the Data
        6. Changing the Data Side of the Bridge
        7. Consequences of the Bridge Pattern
        8. Programs on the CD-ROM
      3. 17. The Composite Pattern
        1. An Implementation of a Composite
        2. Computing Salaries
        3. The Employee Classes
        4. The Subords Class
        5. The Boss Class
        6. Building the Employee Tree
        7. Self-Promotion
        8. Doubly Linked Lists
        9. Consequences of the Composite Pattern
        10. A Simple Composite
        11. Composites in VB
        12. The Composite in VB.NET
          1. The Enumerator
          2. Multiple Boss Constructors
        13. Other Implementation Issues
        14. Programs on the CD-ROM
      4. 18. The Decorator Pattern
        1. Decorating a CoolButton
        2. Using a Decorator
        3. Using ActiveX Controls as Decorators
        4. A Decorator in VB.NET
        5. Nonvisual Decorators
        6. Decorators, Adapters, and Composites
        7. Consequences of the Decorator Pattern
        8. Programs on the CD-ROM
      5. 19. The Façade Pattern
        1. What Is a Database?
        2. Getting Data Out of Databases
        3. Kinds of Databases
        4. ODBC
        5. Microsoft Database Connection Strategies
        6. Database Structure
          1. The DBase Class
        7. Building the Façade Classes
          1. The Stores Class
        8. Building the Stores and Foods Tables
        9. Building the Price Table
          1. Building the Price Query
        10. Summary of the Façade Pattern
        11. ADO Database Access in VB6
          1. The ADO Connection
          2. Adding and Seeking Rows Table Rows
          3. Using the ADO Extensions
        12. The ADO DBase Class
        13. Database Access in VB.NET
        14. Using ADO.NET
          1. Connecting to a Database
          2. Reading Data from a Database Table
          3. Executing a Query
          4. Deleting the Contents of a Table
        15. Adding Rows to Database Tables Using ADO.NET
        16. Making the VB.NET ADO Façade
          1. The DBTable Class
        17. Creating Classes for Each Table
        18. Storing the Prices
        19. Loading the Database Tables
        20. The Final Application
        21. What Constitutes the Façade?
        22. Consequences of the Façade
        23. Programs on the CD-ROM
      6. 20. The Flyweight Pattern
        1. Discussion
        2. Example Code
          1. The Class Diagram
          2. Selecting a Folder
        3. Writing a Flyweight Folder in VB.NET
        4. Flyweight Uses in VB
        5. Sharable Objects
        6. Copy-on-Write Objects
        7. Programs on the CD-ROM
      7. 21. The Proxy Pattern
        1. Sample Code
        2. Writing a Proxy in VB.Net
        3. Proxies in VB
        4. Copy-on-Write
        5. Comparison with Related Patterns
        6. Programs on the CD-ROM
        7. Summary of Structural Patterns
    7. 4. Behavioral Patterns
      1. 22. Chain of Responsibility
        1. Applicability
        2. Sample Code
        3. The List Boxes
        4. Programming a Help System
          1. Receiving the Help Command
        5. A Chain or a Tree?
        6. Chain of Responsibility in VB.NET
        7. Kinds of Requests
        8. Examples in VB
        9. Consequences of the Chain of Responsibility
        10. Programs on the CD-ROM
      2. 23. The Command Pattern
        1. Motivation
        2. Command Objects
        3. Building Command Objects
        4. Arrays of Commands
        5. Consequences of the Command Pattern
        6. Providing Undo
        7. The Command Pattern in VB.NET
        8. The CommandHolder Interface
        9. Handling Undo Commands in VB.NET
        10. The Command Pattern in the VB Language
        11. Programs on the CD-ROM
      3. 24. The Interpreter Pattern
        1. Motivation
        2. Applicability
        3. A Simple Report Example
        4. Interpreting the Language
        5. Objects Used in Parsing
        6. Reducing the Parsed Stack
        7. Implementing the Interpreter Pattern
          1. The Syntax Tree
        8. Building an Interpreter in VB6
        9. The Parse Objects
        10. Consequences of the Interpreter Pattern
        11. Programs on the CD-ROM
      4. 25. The Iterator Pattern
        1. Motivation
        2. Sample VB6 Code
          1. Fetching an Iterator
        3. Filtered Iterators
          1. The Filtered Iterator
        4. Iterators in VB.NET
        5. Consequences of the Iterator Pattern
        6. Programs on the CD-ROM
      5. 26. The Mediator Pattern
        1. An Example System
        2. Interactions between Controls
        3. Sample Code
          1. Initialization of the System
        4. Mediators and Command Objects
        5. The Mediator in VB.Net
          1. Initialization
          2. Handling the Events for the New Controls
        6. Consequences of the Mediator Pattern
        7. Single Interface Mediators
        8. Implementation Issues
        9. Programs on the CD-ROM
      6. 27. The Memento Pattern
        1. Motivation
        2. Implementation
        3. Sample Code
          1. A Cautionary Note
        4. Command Objects in the User Interface
        5. Handling Mouse and Paint Events
        6. Writing a Memento in VB.NET
        7. Consequences of the Memento
        8. Programs on the CD-ROM
      7. 28. The Observer Pattern
        1. Watching Colors Change
        2. Writing an Observer in VB.NET
        3. The Message to the Media
        4. Consequences of the Observer Pattern
        5. Programs on the CD-ROM
      8. 29. The State Pattern
        1. Sample Code
        2. Switching between States
        3. How the Mediator Interacts with the State Manager
        4. Handling the Fill State
        5. Handling the Undo List
          1. Filling Circles in VB6
        6. A State Pattern in VB.NET
        7. Mediators and the God Class
        8. Consequences of the State Pattern
        9. State Transitions
        10. Programs on the CD-ROM
      9. 30. The Strategy Pattern
        1. Motivation
        2. Sample Code
        3. The Context
        4. The Program Commands
        5. The Line and Bar Graph Strategies
        6. Drawing Plots in VB
        7. A Strategy Pattern in VB.NET
        8. Consequences of the Strategy Pattern
        9. Programs on the CD-ROM
      10. 31. The Template Method Pattern
        1. Motivation
        2. Kinds of Methods in a Template Class
        3. Sample Code
          1. Drawing a Standard Triangle
          2. Drawing an Isosceles Triangle
        4. The Triangle Drawing Program
        5. Templates and Callbacks
        6. Summary and Consequences
        7. Programs on the CD-ROM
      11. 32. The Visitor Pattern
        1. Motivation
        2. When to Use the Visitor Pattern
        3. Sample Code
        4. Visiting the Classes
        5. Visiting Several Classes
        6. Bosses Are Employees, Too
        7. Catch-All Operations with Visitors
        8. Double Dispatching
        9. Why Are We Doing This?
        10. Traversing a Series of Classes
        11. Writing a Visitor in VB6
        12. Consequences of the Visitor Pattern
        13. Programs on the CD-ROM
      12. BIBLIOGRAPHY

    Product information

    • Title: Visual Basic Design Patterns: VB 6.0 and VB.NET
    • Author(s): James W. Cooper
    • Release date: November 2001
    • Publisher(s): Addison-Wesley Professional
    • ISBN: 9780201702651