Visual Basic Design Patterns - Bücher versandkostenfrei · Object Oriented Design and Java. ......
Transcript of Visual Basic Design Patterns - Bücher versandkostenfrei · Object Oriented Design and Java. ......
-
Mark GrandBrad Merrill
Visual Basic
Design Patterns
01_268607 ffirs.qxd 6/10/05 10:22 PM Page iii
C1.jpg
-
01_268607 ffirs.qxd 6/10/05 10:22 PM Page ii
-
Visual Basic Design Patterns
01_268607 ffirs.qxd 6/10/05 10:22 PM Page i
-
01_268607 ffirs.qxd 6/10/05 10:22 PM Page ii
-
Mark GrandBrad Merrill
Visual Basic
Design Patterns
01_268607 ffirs.qxd 6/10/05 10:22 PM Page iii
-
Visual Basic Design Patterns
Published byWiley Publishing, Inc.10475 Crosspoint BoulevardIndianapolis, IN 46256www.wiley.com
Copyright 2005 by Wiley Publishing, Inc., Indianapolis, Indiana
Published simultaneously in Canada
ISBN-13: 978-0-471-26860-4ISBN-10: 0-471-26860-7
Manufactured in the United States of America
10 9 8 7 6 5 4 3 2 1
1B/SZ/QW/QV/IN
No part of this publication may be reproduced, stored in a retrieval system or transmittedin any form or by any means, electronic, mechanical, photocopying, recording, scanning orotherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copy-right Act, without either the prior written permission of the Publisher, or authorizationthrough payment of the appropriate per-copy fee to the Copyright Clearance Center, 222Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to thePublisher for permission should be addressed to the Legal Department, Wiley Publishing,Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, (317) 572-3447, fax (317) 572-4355, oronline at http://www.wiley.com/go/permissions.
Limit of Liability/Disclaimer of Warranty: The publisher and the author make no repre-sentations or warranties with respect to the accuracy or completeness of the contents of thiswork and specifically disclaim all warranties, including without limitation warranties of fit-ness for a particular purpose. No warranty may be created or extended by sales or promo-tional materials. The advice and strategies contained herein may not be suitable for everysituation. This work is sold with the understanding that the publisher is not engaged in ren-dering legal, accounting, or other professional services. If professional assistance isrequired, the services of a competent professional person should be sought. Neither thepublisher nor the author shall be liable for damages arising herefrom. The fact that an orga-nization or Website is referred to in this work as a citation and/or a potential source of fur-ther information does not mean that the author or the publisher endorses the informationthe organization or Website may provide or recommendations it may make. Further, read-ers should be aware that Internet Websites listed in this work may have changed or disap-peared between when this work was written and when it is read.
For general information on our other products and services or to obtain technical support,please contact our Customer Care Department within the U.S. at (800) 762-2974, outside theU.S. at (317) 572-3993 or fax (317) 572-4002.
Wiley also publishes its books in a variety of electronic formats. Some content that appearsin print may not be available in electronic books.
Library of Congress Cataloging-in-Publication Data:Grand, Mark.Visual Basic design patterns / Mark Grand, Brad Merrill.
p. cm.Includes bibliographical references and index.ISBN-13: 978-0-471-26860-4 (paper/website)ISBN-10: 0-471-26860-7 (paper/website)1. Microsoft Visual BASIC. 2. BASIC (Computer program language) 3. Software patterns.I. Merrill, Brad. II. Title. QA76.73.B3G683 2005005.2'768--dc22
2005007862
Trademarks: Wiley and the Wiley logo are trademarks or registered trademarks of JohnWiley & Sons, Inc. and/or its affiliates, in the United States and other countries, and maynot be used without written permission. Visual Basic is a registered trademark of MicrosoftCorporation in the United States and/or other countries. All other trademarks are the prop-erty of their respective owners. Wiley Publishing, Inc., is not associated with any product orvendor mentioned in this book.
01_268607 ffirs.qxd 6/15/05 12:34 PM Page iv
www.wiley.com
-
About the Authors
v
Mark Grand is an Atlanta-based consultant specializing in Distributed Systems Object Oriented Design and Java. He was the architect of the first commercial B2B e-commerce product for the Internet. Prior to his involvement with Java, Mark spentover 11 years as a designer and implementer of 4GLs. His most recent role in that veinwas as the architect and project manager for an electronic data interchange product.Mark has worked with a number of MIS organizations in capacities such as SoftwareArchitect, Database Architect and Network Designer.
Mark has been involved with object-oriented programming and design since 1982and is now most widely known for his best-selling patterns books. Mark has taught forU.C. Berkeley, Sun and other organizations. You can find more information aboutMark Grand at http://www.markgrand.com/.
Brad Merrill currently works as a software engineer on the ASP.NET team atMicrosoft. Hes previously worked as a .NET technology evangelist at Microsoft, andas a software engineer at Sybase and Digital Equipment Corporation. His areas of expertise are in distributed systems, transaction processing, operating systems, and compiler technology. Brad lives in Redmond, Washington, and is an avid tourna-ment chess player and bridge player. He can be reached at [email protected] orhttp://www.cybercom.net/~zbrad.
01_268607 ffirs.qxd 6/10/05 10:22 PM Page v
-
01_268607 ffirs.qxd 6/10/05 10:22 PM Page vi
-
Executive EditorRobert M. Elliott
Development EditorsEmilie HermanEileen Bien CalabroAmi Frank Sullivan
Technical EditorsBrad AbramsGeoffrey MrozRod Stephens
Production EditorAngela Smith
Copy EditorFoxxe Editorial Services
Editorial ManagerMary Beth Wakefield
Vice President & Executive GroupPublisher
Richard Swadley
Vice President and PublisherJoseph B. Wikert
Project CoordinatorErin Smith
Graphics and Production SpecialistsApril FarlingCarrie A. FosterDenny Hager Stephanie D. Jumper
Quality Control TechniciansLeeann HarneyJessica KramerJoe NiesenBrian H. Walls
Proofreading and IndexingJohnna Van HooseTECHBOOKS Production Services
Credits
vii
01_268607 ffirs.qxd 6/10/05 10:22 PM Page vii
-
01_268607 ffirs.qxd 6/10/05 10:22 PM Page viii
-
About the Authors v
Credits vii
Introduction xxiiiA Brief History of Patterns xxivOrganization of this Book xxivDescription of Patterns xxv
Pattern Name xxviSynopsis xxviContext xxviForces xxviSolution xxviImplementation xxviConsequences xxvii.NET Usage xxviiCode Example xxviiRelated Patterns xxvii
Who Should Read this Book xxviiWhats on the Companion Web Site xxviii
Chapter 1 Overview of UML 1Class Diagram 2Collaboration Diagram 14Statechart Diagram 22
Chapter 2 The Software Life Cycle 25Case Study 28
Business Case 28Define Requirements Specification 29
Contents
ix
02_268607 ftoc.qxd 6/10/05 10:21 PM Page ix
-
Develop High-Level Essential Use Cases 30Object-Oriented Analysis 32Object-Oriented Design 34
Chapter 3 Fundamental Design Patterns 45Delegation (When Not to Use Inheritance) 47
Synopsis 47Context 47Forces 50Solution 51Implementation 51Consequences 52.NET Usage 52Code Example 52Related Patterns 54
Interface 55Synopsis 55Context 55Forces 56Solution 56Implementation 56
Delegates 57Constructors 57
Consequences 58.NET Usage 58Code Example 58Related Patterns 59
Abstract Base Class 61Synopsis 61Context 61Forces 62Solution 63
AbstractBaseclass 63ConcreteClass1, ConcreteClass2, . . . 64
Implementation 64Consequences 64.NET API Usage 64Code Example 64Related Patterns 67
Interface and Abstract Class 69Synopsis 69Context 69Forces 69Solution 69Consequences 70.NET API Usage 70Code Example 71Related Patterns 72
x Contents
02_268607 ftoc.qxd 6/10/05 10:21 PM Page x
-
Immutable 75Synopsis 75Context 75Forces 76Solution 76Implementation 77Consequences 79.NET API Usage 79Code Example 79Related Patterns 80
Proxy 81Synopsis 81Context 81Forces 82Solution 82Implementation 83Consequences 83Code Example 83Related Patterns 91
Chapter 4 Creational Patterns 93Factory Method 95
Synopsis 95Context 95Forces 97Solution 97Implementation 99
Class Determination by Configuration 99Data-Driven Class Determination 100
Consequences 101.NET API Usage 101Code Example 102Related Patterns 107
Abstract Factory 109Synopsis 109Context 109Forces 110Solution 111Implementation 113Consequences 113Code Example 114Related Patterns 119
Builder 121Synopsis 121Context 121Forces 124Solution 124
Contents xi
02_268607 ftoc.qxd 6/10/05 10:21 PM Page xi
-
Implementation 126The Build Process 126
Consequences 127.NET API Usage 128Code Example 128Related Patterns 129
Prototype 131Synopsis 131Context 131Forces 132Solution 132Implementation 133Consequences 134.NET API Usage 135Code Example 135Related Patterns 139
Singleton 141Synopsis 141Context 141Forces 142Solution 142Implementation 143
Concurrent GetInstance Calls 144Consequences 145.NET API Usage 145Code Example 146Related Patterns 147
Object Pool 149Synopsis 149Context 149Forces 151Solution 152
Reusable 153Client 153ReusablePool 154
Implementation 154Hiding the Object Pool 154Delegating Object Creation 155Ensuring a Maximum Number of Instances 155Data Structure 155Limiting the Size of the Pool 155Managing Stateful Objects 156
Consequences 156Code Example 156Related Patterns 161
xii Contents
02_268607 ftoc.qxd 6/10/05 10:21 PM Page xii
-
Chapter 5 Partitioning Patterns 163Filter 165
Synopsis 165Context 165Forces 166Solution 166Implementation 169Consequences 170.NET API Usage 170Code Example 170Related Patterns 174
Composite 175Synopsis 175Context 175Forces 177Solution 177Implementation 179Consequences 179.NET Usage 180Code Example 180Related Patterns 185
Read-Only Interface 187Synopsis 187Context 187Forces 189Solution 189Implementation 190Consequences 191Code Example 191Related Patterns 192
Chapter 6 Structural Patterns 193Adapter 195
Synopsis 195Context 195Forces 196Implementation 198Consequences 199Code Example 199Related Patterns 204
Iterator 205Synopsis 205Context 205Forces 206Solution 206
Contents xiii
02_268607 ftoc.qxd 6/10/05 10:21 PM Page xiii