5769chFM.qxd
10/13/05
4:21 PM
Page i
Beginning
Object-Oriented
Programming
with VB 2005
From Novice to Professional
Daniel R. Clark
5769chFM.qxd
10/13/05
4:21 PM
Page ii
Beginning Object-Oriented Programming with VB 2005: From Novice to Professional
Copyright © 2006 by Daniel R. Clark
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means,
electronic or mechanical, including photocopying, recording, or by any information storage or retrieval
system, without the prior written permission of the copyright owner and the publisher.
ISBN (pbk): 1-59059-576-9
Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1
Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence
of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark
owner, with no intention of infringement of the trademark.
Lead Editor: Jonathan Hassell
Technical Reviewer: Jon Box
Editorial Board: Steve Anglin, Dan Appleman, Ewan Buckingham, Gary Cornell, Tony Davis, Jason Gilmore,
Jonathan Hassell, Chris Mills, Dominic Shakeshaft, Jim Sumser
Project Manager: Beth Christmas
Copy Edit Manager: Nicole LeClerc
Copy Editors: Marilyn Smith and Ami Knox
Assistant Production Director: Kari Brooks-Copony
Production Editor: Janet Vail
Compositor: Kinetic Publishing Services, LLC
Proofreader: Christy Wagner
Indexer: Rebecca Plunkett
Artist: Kinetic Publishing Services, LLC
Cover Designer: Kurt Krames
Manufacturing Director: Tom Debolski
Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor,
New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail , or
visit .
For information on translations, please contact Apress directly at 2560 Ninth Street, Suite 219, Berkeley, CA
94710. Phone 510-549-5930, fax 510-549-5939, e-mail , or visit .
The information in this book is distributed on an “as is” basis, without warranty. Although every precaution
has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to
any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly
by the information contained in this work.
The source code for this book is available to readers at in the Source Code section.
5769chFM.qxd
10/13/05
4:21 PM
Page iii
Contents at a Glance
About the Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
About the Technical Reviewer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
PART 1
■CHAPTER
■CHAPTER
■CHAPTER
■CHAPTER
PART 2
■CHAPTER
■CHAPTER
■CHAPTER
■CHAPTER
■CHAPTER
PART 3
■■■
1
2
3
4
Overview of Object-Oriented Programming . . . . . . . . . . . . . . . . . . . . . . 3
Designing OOP Solutions: Identifying the Class Structure . . . . . . . 11
Designing OOP Solutions: Modeling theObject Interaction . . . . . . . 31
Designing OOP Solutions: A Case Study . . . . . . . . . . . . . . . . . . . . . . . . . 63
■■■
5
6
7
8
9
Object-Oriented Programming
and Design Fundamentals
Object-Oriented Programming
with Visual Basic
Introducing Visual Basic and the .NET Framework . . . . . . . . . . . . . . 85
Creating Classes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Creating Class Hierarchies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
Implementing Object Collaboration . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
Working with Collections. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
■■■
Developing Applications
with Visual Basic
■CHAPTER 10 OSO Application Revisited: Implementing the Business Logic . . . 201
■CHAPTER 11 Developing Windows Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
■CHAPTER 12 Developing Web Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
iii
5769chFM.qxd
10/13/05
4:21 PM
Page iv
■CHAPTER 13 Developing and Consuming Web Services . . . . . . . . . . . . . . . . . . . . . 311
■CHAPTER 14 Wrapping Up and Reviewing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325
PART 4
■■■
■APPENDIX A
■APPENDIX B
■APPENDIX C
Appendixes
Fundamental Programming Concepts . . . . . . . . . . . . . . . . . . . . . . . . . 331
Exception Handling in VB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347
Installing the Sample Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
■INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355
iv
5769chIDX.qxd
10/13/05
4:26 PM
Page 367
■INDEX
use cases, 14–21
actors in, 14
creating OSO, 65–66
defined, 12
developing from SRS, 14, 17–18
diagramming, 17–21
diagramming OSO application, 66–68
illustrated, 14, 15, 16, 29
inclusion, 16
modeling class behaviors for OSO
application, 73–77
user groups, 327
■V
validating employees, 232, 269–270, 305–306
variables, 331
block-level scope of, 336
module scope of, 337
procedure scope of, 337
View Supply Catalog scenario, 76
views in Solution Explorer, 94–98
Visual Basic .NET. See also fundamental
programming concepts; object
collaboration
defining classes, 110–114
delegated methods, 156–158
derived class in, 124
developing programming skills, 325–327
history of, 8–9
inheritance, 7, 123–129
issuing event messages in, 150
method definitions in, 148
origins of, 8–9
polymorphism, 7, 123, 140–145
procedures, 344–345
support for generic-based collections, 193
Visual Studio
building and executing assemblies, 102
creating base and derived classes,
126–127
debugging in, 103–107
defining classes, 113–114
designing forms in, 100–101
exploring Toolbox, 99–101
form designer in, 240–243
IDE in, 92–93
new projects in, 94
shared methods in, 164–166
Solution Explorer views, 94–98
verifying database installation with,
352–354
Web Page Designer, 279–281
■W
warning dialog box, 288
Watch window (Visual Studio), 106
Web Forms
about, 275–277
adding page and server control event
handlers, 281–283
code-behind files, 276–277
creating OSO Web-based interface,
303–310
displaying OSO products, 303–304
enabling debugging for Web files, 287–288
inheritance for web pages and Web server
controls, 277–279
initiating OSO Web orders, 304–305
OSO order items added to, 306–308
placing orders on OSO, 309
removing items from OSO, 308–309
server-side event processing, 283–284
similarity to Windows Forms interfaces,
275
testing OSO Web GUI, 309–310
using Web server controls, 277
validating OSO employees at login,
269–270, 305–306
Web Page Designer (Visual Studio)
Toolbox for, 286
using, 279–281
web pages
inheritance hierarchy of, 277–279
interface and programming logic of,
275–277
web references for web services, 320, 322
Web server controls, 277–279
web services. See also consuming web
services
about, 311–312, 323
adding web references, 320, 322
browsing for, 320
consuming, 319–323
creating, 313–319
processes in, 312–313
WebControl class, 279
While statements, 342–343
Windows Forms
adding dialog box to close application,
258–259
creating inherited forms, 257–258
data binding, 260–266
dialog box vs. normal, 252
event-driven model of, 243
inheritance hierarchy for form classes,
238–239
similarity to Web Forms interfaces, 275
types of controls on, 238
working with, 237–238
Withdraw method
testing, 128–129, 134, 135–136
using MyBase qualifier with, 135
367
5769chIDX.qxd
368
10/13/05
4:26 PM
Page 368
■INDEX
WithEvents declaration, 152–153
WithEvents keyword, 150
WSDL files, 315, 316
■X
XML (Extensible Markup Language)
about ADO.NET and, 88–89
ADO.NET and data structure of, 88–89, 203
.NET Framework support for standards,
86, 203
persisting DataSet objects to XML file,
220
serializing/deserializing .NET data types,
149