1. Trang chủ
  2. » Công Nghệ Thông Tin

Visual Basic 2005 Design and Development - Chapter 1 potx

38 299 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Visual Basic 2005 Design and Development
Tác giả Rod Stephens
Trường học Wiley Publishing, Inc.
Chuyên ngành Microsoft Visual Basic
Thể loại sách
Năm xuất bản 2007
Thành phố Indianapolis
Định dạng
Số trang 38
Dung lượng 603,92 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

pro-Stephens has written 15 books that have been translated into half a dozen different languages, and morethan 200 magazine articles covering Visual Basic, Visual Basic for Applications

Trang 1

Expert One-on-One ™

Design and Development

Trang 3

Expert One-on-One ™

Design and Development

Rod Stephens

Trang 4

Copyright © 2007 by Wiley Publishing, Inc., Indianapolis, Indiana

Published by Wiley Publishing, Inc., Indianapolis, Indiana

Published simultaneously in Canada

LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO REPRESENTATIONS

OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PAR- TICULAR PURPOSE NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES OR PROMOTIONAL MATERIALS THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR EVERY SITUATION THIS WORK IS SOLD WITH THE UNDERSTANDING THAT THE PUBLISHER IS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR OTHER PROFESSIONAL SERVICES IF PROFESSIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF A COMPETENT PRO- FESSIONAL PERSON SHOULD BE SOUGHT NEITHER THE PUBLISHER NOR THE AUTHOR SHALL BE LIABLE FOR DAM- AGES ARISING HEREFROM THE FACT THAT AN ORGANIZATION OR WEBSITE IS REFERRED TO IN THIS WORK AS A CITATION AND/OR A POTENTIAL SOURCE OF FURTHER INFORMATION DOES NOT MEAN THAT THE AUTHOR OR THE PUBLISHER ENDORSES THE INFORMATION THE ORGANIZATION OR WEBSITE MAY PROVIDE OR RECOMMENDATIONS

IT MAY MAKE FURTHER, READERS SHOULD BE AWARE THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE CHANGED OR DISAPPEARED BETWEEN WHEN THIS WORK WAS WRITTEN AND WHEN IT IS READ.

For general information on our other products and services please contact our Customer Care Department within the United States at (800) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.

Trademarks:Wiley, the Wiley logo, Wrox, the Wrox logo, Programmer to Programmer, Expert One-on-One, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc and/or its affiliates, in the United States and other coun- tries, and may not be used without written permission Visual Basic is a registered trademark of Microsoft Corporation in the United States and/or other countries All other trademarks are the property of their respective owners Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book.

Trang 5

Quality Control Technician

Laura Albert

Proofreading and Indexing

ConTextTechbooks

Trang 6

About the Author

Rod Stephens started out as a mathematician but, while studying at MIT, discovered the joys of gramming, and has been programming professionally ever since During his career, he has worked on aneclectic assortment of applications in such fields as telephone switching, billing, repair dispatching, taxprocessing, wastewater treatment, and training for professional football players

pro-Stephens has written 15 books that have been translated into half a dozen different languages, and morethan 200 magazine articles covering Visual Basic, Visual Basic for Applications, Delphi, and Java Hewrites three weekly newsletters (www.vb-helper.com/newsletter.html) that contain quick tips,tricks, and examples for Visual Basic developers

His popular VB Helper Web site (www.vb-helper.com) receives several million hits per month, and tains thousands of pages of tips, tricks, and example code for Visual Basic programmers, as well asexample code for this book

con-Currently, Stephens is an author, consultant, and instructor at ITT Technical Institute

Other Books by Rod Stephens

Visual Basic 2005 Programmer’s Reference ISBN: 0-7645-7198-2Visual Basic NET and XML ISBN: 0-471-12060-XVisual Basic Graphics Programming, Second Edition ISBN: 0-471-35599-2Bug Proofing Visual Basic Graphics ISBN: 0-471-32351-9Custom Controls Library ISBN: 0-471-24267-5Ready-to-Run Visual Basic Algorithms, Second Edition ISBN: 0-471-24268-3Ready-to-Run Visual Basic Code Library ISBN: 0-471-33345-X

Trang 7

Thanks to Bob Elliott, Kevin Shafer, and all of the others who make producing any book possible.Thanks also to technical editor John Mueller for making sure I wasn’t putting my foot too deeply in mymouth and for helping to add extra depth to the book Visit http://www.mwt.net/~jmuellerto learn

about John’s books and to sign up for his free newsletter NET Tips, Trends & Technology eXTRA.

Trang 8

Contents

Trang 9

Chapter 2: Lifecycle Methodologies 15

Trang 11

Chapter 6: Data Storage Design 133

Part II: Meta-Development 203

Trang 13

Chapter 11: Property Support 297

Trang 14

Chapter 14: Development Philosophy 391

Trang 15

Chapter 16: Bug Proofing 435

Trang 16

Part IV: Specific Techniques 493

Trang 17

Chapter 22: Reflection 559

Trang 18

Visual Basic 2005, together with the NET Framework, provides a wonderfully powerful developmentenvironment With these tools, developers can build amazingly powerful applications relatively quicklyand easily

With this power, however, comes great complexity Many books are available that discuss the VisualBasic language, and if you need to build a relatively simple application, those are generally sufficient

No books, however, address the complex issues that surround the development of more complicatedVisual Basic applications None discuss design, modeling, user-interface design, or testing for VisualBasic applications

These books also don’t cover some of the important advanced topics that don’t fit well into introductorybooks They generally don’t have the time to cover threading, reflection, advanced memory management,and printing in the depth necessary to make them useful for building really advanced applications

Expert One-on-One Visual Basic 2005 Design and Development fills the gaps that these books leave

sur-rounding Visual Basic development It explains the design activities that are necessary before VisualBasic development can begin It covers processes that occur after development (such as deployment,update management, and testing) that are essential to a successful Visual Basic project, but that are notpart of the language itself Finally, it covers advanced topics that are useful in real-world applications,but that are given little attention in other books

Why Visual Basic?

A Visual Basic programmer’s joke asks, “What’s the difference between Visual Basic NET and C#?About three months!” The implication is that Visual Basic NET syntax is easier to understand, andbuilding applications with it is faster Similarly, C# programmers have their jokes about Visual Basic,implying that C# is more powerful

In fact, Visual Basic is not a whole lot easier to use than C#, and C# is not significantly more powerful.

The basic form of the two languages is very similar, aside from a few stylistic differences A good C# grammer can crank out a small application as quickly as a Visual Basic developer can, and a good VisualBasic programmer can churn out object hierarchies and graphics code as effectively as a C# developer.What many developers forget, however, is that building a successful application goes far beyond spittingout mountains of code The code must work today, tomorrow, and for the entire life of the application.Far more important than the programming language is the way developers use the language I have seencode written in C, FORTRAN, and even assembly language that was so well structured and documentedthat practically anyone could modify the code with a minimal chance of adding obscure bugs I’ve alsoseen a 56,000-line Visual Basic project that was so poorly designed and documented that even develop-ers who had worked with the project for years could spend a week or more making a simple change,and have about a 50 percent chance of adding new bugs that would take another week or two to fix

Trang 19

pro-So, does that mean your choice of language is irrelevant? Almost, but not quite First, the developmentenvironment plays a very important role in modern application development Visual Studio providesunmatched tools for programming, debugging, and refactoring code IntelliSense makes it easier toremember what parameters a routine needs Auto-completion makes it easy to use longer, more descrip-tive variables Design-time syntax-checking highlights suspicious code as you type it XML commentsand attributes let you make classes, methods, and events even more self-documenting than ever before.All of these tools make writing effective, reliable, maintainable code in the Visual Studio languagesmuch easier than in many other languages that have less support from their development environments.Though Visual Studio provides all of these tools, it cannot force you to use them properly, and hereVisual Basic gives you a slight edge Visual Basic has always been a very descriptive language Its key-words are reasonably self-documenting and provide extra context to help you figure out what’s going

on A piece of C# or C++ code containing several nested loops inside a subroutine may end with a series

of many closing brackets There’s no extra information to help you remember what the brackets are ing You can (and should) add comments to make this obvious, but the language doesn’t force you to, somany programmers don’t bother

end-In contrast, Visual Basic ends a block of code with appropriate End Do, End If, End Sub, and otherstatements that make it obvious what type of block is ending Although you should still add comments

to indicate the purpose of the block of code that is ending, Visual Basic provides some basic annotation

by itself

Because Visual Basic is more descriptive than the other Visual Studio languages, it encourages ers to adopt a more descriptive style, too Every time you write a Forloop, you see keywords that helpconfirm the purpose and extent of the loop Visual Basic is transparent, so developers are more inclined

develop-to make their own code transparent

(The NET Framework also sets a good example by providing long, descriptive variable, class, method,and event names Class names such as SortedListand method names such as DrawRectangleare soeasy to understand that it’s easy to adopt similar habits of writing descriptive names.)

No programming language can force you to write good code But Visual Studio provides powerful toolsthat reduce barriers to writing good code They make it so easy to construct self-descriptive code thatthere’s no excuse to write dense, opaque code full of obscure, inconsistent abbreviations By performingits own chores in a self-descriptive way, Visual Basic gives you a little extra help in keeping your owncode lucid Use C# if you like, but I prefer to grab every advantage available

Who Should Read This Book

This book is intended for advanced Visual Basic programmers It assumes that you already have ence with Visual Basic 2005 and are comfortable with the language The book does not cover any languagefundamentals, and does not include any refresher material If you feel that you need more experience with

experi-Visual Basic, see my book experi-Visual Basic 2005 Programmer’s Reference (Indianapolis: Wiley, 2005).

The topics I present in this book are as advanced as possible In some cases, however, I have includedsimpler code to give background for a more advanced topic But the goal of every part of the book is toexplain advanced material that is either complex, hard to find in other places, or both

Trang 20

Note that not all advanced material is complicated or difficult to understand For example, the followingstatement summarizes one of the most important concepts in this entire book:

In fact, this statement is so important that if you learn nothing else from this book, you will havereceived your money’s worth However, once you truly understand this idea (which I’ll discuss furtherlater in the book, notably in Chapter 14, “Development Philosophy”), it’s completely obvious Still, this

is an advanced concept I have never seen it written down explicitly in another book, and many ers only figure it out after years of debugging other people’s code

develop-How This Book Is Organized

This book’s chapters are grouped into four parts

Part I: Design

The chapters in this part of the book cover activities that occur before programming begins Theydescribe development and design approaches, and some useful design techniques Many programmersskimp on these phases, and later pay a huge price when their initial assumptions prove inappropriatefor the application

Chapter 1, “Language Selection,” describes some of the issues that you should consider when picking adevelopment language The book assumes you will use Visual Basic, but this chapter describes some ofthe language’s shortcomings While you may stick with Visual Basic, it’s worth understanding some ofthe language’s weak spots, and what you can do about them If you know where trouble may arise, youcan more easily cope with it In extreme cases, you may be able to move some of the more troublesomemodules into a library written in another language and call the library from your Visual Basic code.Chapter 2, “Lifecycle Methodologies,” discusses different lifecycle methodologies such as the waterfall,iterative prototyping, and staged delivery models It explains why Visual Basic is a particularly goodtool for building applications iteratively Most developers become accustomed to a particular methodol-ogy and never change Even if you know you will be using iterative prototyping to build your applica-tion, it’s worth taking the time to understand the best features of alternative approaches so that you cantry to steal the best ideas from them all

Chapter 3, “Agile Methodologies,” explains different development strategies, such as agile ment methods like extreme programming (XP), test-first development, and design by contract (DBC)

develop-It includes references to information on Microsoft’s Web sites about using Visual Studio for agile development

Chapter 4, “Object-Oriented Design,” discusses issues in object-oriented design It introduces theUniversal Modeling Language (UML) and gives some tips for designing an object-oriented system Itexplains how Visual Studio Team Suite and Visual Studio Team Architect support UML, and mentions afew other UML tools that developers can use It tells how to gain a complete understanding of an appli-cation by viewing design from different perspectives, such as user interface, document, and data per-spectives It explains how to get the greatest benefit from object-oriented ideas, such as encapsulation,polymorphism, loose coupling, and component-oriented design

Programs are written for people, not computers.

Trang 21

Chapter 5, “User-Interface Design,” explains important user-interface concepts It explains the rule of

7 +/– 2 and tells how to use containers such as tab strips and scrolling controls to display large amounts

of data It discusses the merits and drawbacks of SDI and MDI applications, and examines menus, bars, and keyboard shortcuts It also explains techniques for customizing the user interface for particularusers and locales

tool-Chapter 6, “Data Storage Design,” discusses different data storage and retrieval strategies It exploresoptions such as relational databases, XML, flat text files, the System Registry, compiled in data, resourcefiles, and INI files It explains how a program can serialize and deserialize its data Note that this chapterdoes not cover relational database design in depth For example, it does not explain normalization andindexing in great detail, instead referring to other books for more information

Chapter 7, “Design Patterns,” provides an introduction to design patterns and anti-patterns in VisualBasic It explains what design patterns and anti-patterns are, describes some of the most useful, and

refers the reader to other books such as Visual Basic Design Patterns by Mark Grand and Brad Merrill

(Indianapolis: Wiley, 2005) for additional details

Part II: Meta-Development

The chapters in this part of the book discuss writing tools that are used by application developers Theseinclude add-ins that give design-time support to developers, custom controls and components that can

be placed on forms, and techniques that let the user execute scripts at run-time A good library of development tools makes later development easier and less error-prone

meta-Chapter 8, “Snippets, Macros, and Add-ins,” explains how to write add-ins for the Visual Basic 2005development environment It briefly describes code snippets and explains when it is appropriate to usethem rather than add-ins

Chapter 9, “Scripting,” explains how a program can allow the end user to write and execute scripts Ittells how to let the user execute SQL statements, VBA code, and VB NET scripts It explains how a pro-gram can expose its object model so that the user can control it with VB NET scripting This chapter alsotells how a developer can use the same scripting techniques to give an application new functionalityafter it has been compiled

Chapter 10, “Custom Controls and Components,” explains how to build custom controls It describes thethree main approaches for building custom controls: UserControl, subclassing, and from scratch Italso explains how to build a special particularly useful type of custom control called extender providers,

and includes examples of some extremely useful data validation extender providers.

Chapter 11, “Property Support,” explains how to build custom property editors for use by custom trols It also tells how to use type converters to allow editors such as the Properties window at designtime and the PropertyGridcontrol at run-time to edit complex properties of an object

con-Chapter 12, “Attributes and XML Comments,” explains useful attributes that you can use to “decorate”code These attributes make extra information available to other developers (or yourself) who use thecode later so that it is easier to use the code correctly

Ngày đăng: 14/08/2014, 11:20

TỪ KHÓA LIÊN QUAN