Summary of Contents Introduction Chapter 1: Introduction to Design Patterns Chapter 2: Design Patterns in the Data Tier Chapter 3: Design Patterns in the Middle Tier Chapter 4: Design Patterns in the Presentation Tier Chapter 5: Between the Tiers: Design Patterns and .NET Remoting Chapter 6: What Next? Appendix A: UML Primer Index Professional Design Patterns in VB.NET: Building Adaptable Applications Tom Fischer John Slater Pete Stromquist ChaurG. Wu APress Media, LLC Professional Design Patterns in VB.NET: Building Adaptable Applications © 2002 by Apress Originally published by Apress in 2002 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 978-1-59059-274-8 ISBN 978-1-4302-0783-2 (eBook) DOI 10.1007/978-1-4302-0783-2 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. Distributed to the book trade in the United States by Springer-Verlag New York, Inc., 175 Fifth Avenue, New York, NY, 10010 and outside the United States by Springer-Verlag GmbH & Co. KG, Tiergartenstr. 17, 69112 Heidelberg, Germany. In the United States: phone 1-800-SPRINGER, email [email protected], or visit http://www.springer-ny.com. Outside the United States: fax +49 6221 345229, email [email protected], or visit http://www.springer.de. 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, email [email protected], or visit http://www.apress.com. 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 http://www.apress.com in the Downloads section. Credits Editorial Board Commissioning Editor Dan Appleman Paul Jeffcoat Craig Berry Gary Cornell Managing Editors Tony Davis Viv Emery Steven Rycroft Laurent Lafon Julian Skinner Martin Streicher Project Manager Jim Sumser Emma Batch Karen Watterson Gavin Wray Author Agent John Zukowski Nicola Phillips Additional Material Production Coordinator Richard Blair Sarah Hall Ian Nutt Production Assistant Technical Reviewers Neil Lote Richard Blair Maxime Bombardier Cover Cristof Falk Kurt Krames Damien Foggon Mark Horner Index David Sussman Adrian Axinte Mike Walston Proofreaders Technical Editors Fiona Berryman Dev Lunsford Chris Smith Dan Maharry Ian Nutt About the Authors Tom Fischer Tom Fischer's career spans a broad range of technologies, working with some of the most prestigious consulting firms in the Twin Cities. His certifications include the Sun Certified Java Programmer (SejP), Microsoft Certified Solution Developer (MCSD), and Microsoft Certified Database Administrator (MCDBA). As a Microsoft Certified Teacher (MCT), Tom also helps teach other developers about the latest .NET tools and technologies. I would like to dedicate my contributions to Theresa, Ali, and Kate. They are the greatest! - TF John Slater John Slater is a project manager at Management Reports International in Cleveland, OH. At MRI he is currently developing applications for the property management industry. Right now, he is working on several projects using .NET development tools and .NET Enterprise servers. In his free time John enjoys outdoor activities and playing with his children Rachel and Nathan. He can be reached [email protected]. Pete StromquIst Pete Stromquist is a consultant at Microsoft Technologies (one of the nation's premier Microsoft Certified Solution ProViders), specializing in web-enabled application development using Microsoft tools and technologies. He has spent the last several years architecting and developing the following types of applications: intranet content management, web-enabled training and testing software, B2B and B2C e-commerce, and web-based telemetry and logistics. He has complemented his VB skills with several other technologies such as: XML, XSL, COM+, lIS, ASP, and of course .NET. Pete also enjoys teaching and presenting on .NET technologies. He has a Mechanical Engineering background, and received his Bachelor of Science from the University of Minnesota. ChaurG. Wu Chaur Wu currently works for Trend Micro Inc. as a senior software engineer. He started software programming before he was old enough to qualify for a driving license. The first program he wrote was a bingo game - in assembly code on an 8051 Single chip. To capitalize on the program, he ran a small casino in the lab - he developed primitive game boxes that connected his pals and allowed them to place bets. He's also been involved in much larger projects. For example, he developed a program in C++ to simulate the movement and geographical coverage of GPS satellites. As a research assistant in his graduate study, he implemented a wavelet-based video compression algorithm for a traffic surveillance system sponsored by Boston City Department of Transportation. He also helped solve a blurred image problem using inverse filters and other image processing algorithms for a client who designs fiber optics components in San Jose, CA. His technical interests include distributed software systems inJava, COM, and .NET, generative programming, software deSign, and neural networks. Outside of work, his favorite vacation combines a one-night gambling trip to Reno followed by a day of skiing at some resort near Lake Tahoe. You can email [email protected]. I would like to dedicate my efforts in this book to my two-year-old daughter, Sarah. -CGW r- - --==---------r-f.~-~... . -.- · · ,• • · .'. -..... -~. .0- Table of Contents Introduction 1 Who Is This Book For? 2 What Does This Book Cover? 2 What This Book Does Not Cover 3 What You Need to Use This Book 3 Style Conventions 4 Customer Support and Feedback 5 Source Code and Updates 5 Errata 6 forums.apress.com 6 Chapter 1: Introduction to Desl@ Patterns 9 What Is a Design Pattem? 10 Catalogs of Patterns 10 The Gang of Four 10 Other Catalogs and Resources 11 Design Patterns and Visual Basic 11 The Arrival of VB. NET 12 When Should we use Design Patterns? 12 How a Design Pattern can Improve a Design 13 The Actional TakeHomePay Application 13 The Building Blocks 16 Creational Patterns 17 The Singleton Design Pattem 18 The Abstract Factory Design Pattem 21 The Factory Method Design Pattem 26 Structural Patterns 29 The Adapter and Fagade Design Pattems 29 The Bridge Design Pattem 34 The Composite Design Pattem 39 The Decorator Design Pattem 43 The Proxy Design Pattem 49 Behavioral Patterns 51 The Observer Design Pattem 52 The State Design Pattem 55 The Strategy and Template Method Design Patterns 60 Table of Contents Application of Design Patterns 64 Pattern Selection 64 Summary 66 Chapter 2: Design Patterns in the Data Tier 69 Requirements of a Data Tier 70 A Requirements List 71 Analysing the Requirements 71 Data-Tier Architecture 72 A Simple but Inflexible Data-Tier Example 72 A Slightly More Maintainable Example 74 Creating a Flexible Data Access Framework 75 The . NE T Data Providers 75 The .NET Data Provider Objects 76 The Design Patterns Analysis 77 Building the Data Tier 82 A UML Class Diagram 83 Building the Output Classes 84 The Abstract Base Output Classes 84 The Concrete Product Classes 85 Building the Factory Classes 88 The Abstract Factory Class 88 The NWDSARequest Helper Class 89 Managing Connection Strings 92 The Concrete Factory Classes 95 Compiling the Data Tier Application 103 Testing the Data Tier Application 104 A Simple Windows Test Application 104 Building the Application 104 Testing the SQL Server .NET Data Provider 109 Testing the OLE DB .NET Data Provider 109 Testing the ODBC .NET Data Provider 110 A Simple Web Test Application 111 Summary 114 Chapter 3: Design Patterns In the Middle Tier 117 Handling Orders 118 Business Requirements 118 Technology Requirements 119 Analysis and Design 119 Use Case Diagrams 120 Activity Diagrams 121 Homing in on Patterns 122 Sequence Diagrams 124 Class Diagrams 125 ii
Description: