Visual Basic Developer's Guide to UML and Design Pattern

Alpha 2001-01-04 04:23:00
Visual Basic Developer's Guide to UML and Design Patterns
by Yair Alan Griver, Matthew Arnheiter, and Michael Gellis
Sybex, Inc.
ISBN: 0782126928 Pub Date: 06/01/00 INTRODUCTION
Welcome to our latest book. This introduction will discuss the purpose of this book and the various sections into which it has been divided. Designing an application is a complex task and, over time, as applications have become more complex, certain standards for analyzing business problems and designing the software solutions to fix them have come to the forefront. This book covers two of those standards, design patterns and the Unified Modeling Language (UML) diagrams used to document them.

Who Should Read This Book?
This book is geared towards intermediate to advanced Visual Basic (VB) developers, especially those who have a pre-existing interest in design patterns, but haven’t been able to understand the samples that have typically been shown in C++ or Java. Our goal is that this book will allow you to understand the patterns that are commonly referred to in the object-oriented world, and will give you a good working knowledge of both when to use those patterns in your own development efforts and how to use them effectively in Visual Basic.

How This Book Is Organized
The first part of this book deals with design patterns, a method of cataloging good design in application development. It also touches upon the way certain UML diagrams are used to catalog those patterns. The core of the book provides a catalog of various design patterns that can be used in your day-to-day design and development efforts. Each chapter uses the same basic outline:

• An introduction to the pattern
• A discussion (when necessary) of the different approaches to the pattern
• A UML diagram of the pattern and how it works
• Sample uses of the pattern, including the VB code that is used
• Other uses of the pattern
• A list of related patterns
• A conclusion
It is our hope that you will be able to use this book as a quick reference guide when you are considering a new piece of functionality for an application. The contents of this book should provide you with ideas for various ways to achieve functionality in your specific implementation.

Part 1: Introduction to Using UML and Design Patterns in Visual Basic
The first section of the book introduces UML, design patterns, and some basic techniques for how to use design patterns in Visual Basic. Chapter 1, “An Introduction to UML,” provides a general overview of UML with a particular focus on the diagrams that are used in cataloging design patterns. Chapter 2, “An Introduction to Design Patterns,” discusses the history of design patterns and the goals of this book, as compared to those of the book that began the discussion of this subject: Design Patterns: Elements of Reusable Object-Oriented Software, by Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides, and Grady Booch. Finally, Chapter 3, “Visual Basic and Design Patterns,” discusses some basic VB techniques, including implementing interfaces, that are useful in creating the patterns discussed in the book.

Part 2: Structural Patterns
The second part of the book discusses structural patterns, those design patterns that describe how objects interact with each other. In other words, these chapters focus on the architectural framework of the objects. We focus on seven architectural patterns: bridge, adapter, composite, decorator, facade, flyweight, and proxy.

A bridge pattern allows you to separate an interface from its implementation, so that the two can vary independently. You would use a bridge pattern when you want to vary the implementation of a particular method at run time, but you don’t want to recompile the client code. This pattern also allows you to standardize an implementation across multiple classes by bridging all the interface classes to one implementation object.

The adapter pattern, also known as a wrapper pattern, allows two objects to communicate even though they have incompatible interfaces. Adapter accomplishes this by using an intermediary object that is compliant with the client object and delegates the execution of the client requests to the incompatible server object.

The composite pattern provides a unified interface that both collection classes and leaf node classes can inherit. By defining one interface, clients can treat items and collections uniformly within a hierarchy. Client code can recursively iterate through a part-whole hierarchy without having to write separate code to distinguish between the collections and primitives. The composite pattern eliminates the need to write case statements that depend on the type of class when traversing a hierarchy.

The decorator pattern allows you to assign additional responsibilities to an object without subclassing. It allows an object to add new functionality to another object dynamically. As a result, you can use the decorator pattern as an alternative to implementation inheritance. The decorator pattern encloses an object within a decorator object; this decorator object adds additional functionality without modifying the interface of the original object. Since the interface is not modified—and must be implemented completely by the decorator object—you can stack multiple decorators. This stacking provides layers of functionality that are added dynamically to a component.

The facade pattern provides a relatively simple interface to a complex subsystem or set of subsystems. Facade is used when a system provides its services through multiple subsystems or through calling multiple procedures. In order for clients to use the services of the system, they would have to be familiar with the intricacies of its subsystems and procedures. Facade shields clients from the intricacies of the subsystems by providing a simple interface for clients to call. In turn, the facade makes the necessary calls to its constituents to provide the service.

The flyweight pattern provides a method to pool and share a large number of contexts. It allows a single object to be used in several contexts simultaneously. This pattern allows you to design applications from an object-oriented view without the cost of instantiating a large number of objects, which could be prohibitive and inefficient.

The proxy pattern provides a surrogate object that delegates method calls to another object. It acts like a placeholder for an object that can be used to efficiently control access to the other object. The proxy mimics the other object to the extent that the client does not know that it is communicating with a proxy. The proxy pattern is used whenever you need an object to receive method calls on behalf of another object.

Part 3: Behavioral Patterns
Part 3 focuses on behavioral patterns, which describe how you can use objects to change the behavior of a system at run time. These are the most useful patterns to the VB developer, and we focus on twelve of these patterns: observer, mediator, chain of responsibility, command, interpreter, iterator, visitor, template, hook, memento, state, and strategy.

The observer pattern defines a one-to-many dependency between objects so that when one object changes state, all of its dependents are notified and updated automatically. There are two main types of observers: pull observers and push observers. The difference between the two is in how the observer relates to its subject or subjects. A pull observer is an active observer that pulls in the state of its subjects. In contrast to a pull observer, a push observer is a passive observer that needs its subjects to send notification messages in order for the observer to perform its role of updating a client.

The mediator pattern creates an object (the mediator) that acts like a traffic cop, controlling the interaction between a set of objects. The mediator encapsulates the rules of interaction between the set of objects. This is accomplished by loosely coupling the objects: the objects are not aware of each other; they are only aware of the mediator object. All “traffic” goes through the mediator.

The chain of responsibility pattern is an extremely flexible and extensible pattern. This pattern decouples the sender of a request from its receiver by giving more than one object a chance to handle the request. The request is passed along a group or “chain” of objects. Use the chain of responsibility pattern when more than one object can handle a request, but the requesting object does not know which object should answer the request.

The command pattern is used to turn a client procedure call into an object. Command gives the procedure request a life of its own so that it can have its own behaviors and properties. The command object does not carry out the request; rather it receives the request from the client, performs the functionality that it was designed to do, and then passes the request to the server object that is able to carry out the client's request. The command pattern allows you to add intelligence and behavior to procedure calls without modifying the client or server.

The interpreter pattern is used to help an application understand a natural language statement and execute the intended functionality of the statement. Interpreter-type functionality is used every day by developers in the form of code compilers and utilities that execute SQL statements. You can use many algorithms to provide this functionality; some algorithms provide good performance while others minimize resource consumption. The benefit of interpreter is in the flexibility it provides. It allows you to easily add new syntax rules and multiple implementations of a statement.

The iterator pattern provides a method to sequentially access members of a collection. This pattern separates the traversal mechanism and state management from an aggregate object. It removes the interface to traverse a group of objects from the aggregate object without revealing the underlying representation. Removing the mechanism to iterate through the collection allows different algorithms to be used to step through the collection (for example a forward iteration and a reverse iteration) without bloating the collection interface. In addition, the iterator pattern allows multiple clients to iterate through the same collection and be at different points.

The visitor pattern is used when operations must be performed upon numerous elements of an object model. Without the visitor, this type of functionality is usually implemented by spreading the required operations throughout the object model. Visitor provides a clean and more flexible model by abstracting the operations from the elements of the object model, and turning them into visitor objects. The visitor objects traverse the object model and perform their respective operations upon the individual elements. The visitor pattern allows you to keep an object model neat by abstracting into separate objects the operations which have to be performed on the elements of the model. It also allows you to easily add or remove operations without touching the elements of the model.

The template method pattern is a simple, yet fundamental, pattern for code reuse. The key to this pattern is putting the skeleton of an algorithm within a method (the template method). Steps in the algorithm become methods called from the template method. This keeps the overall algorithm constant, while allowing you to change how the individual steps of the algorithm are carried out. Template is best suited for when you are implementing a defined algorithm. It helps you avoid spaghetti code by standardizing the steps of the code first and then implementing each individual step.

The hook pattern allows developers in the future, after the original code has been written, to implement currently unforeseen functionality. A hook is simply a call from within a working procedure to an unimplemented procedure, meaning a procedure that consists of only the procedure stub without any implementation code. The call to the procedure is known as the hook and the empty procedure is known as the hook operation. The hook operation is where code for future functionality will be written.

The memento pattern is used when an object needs to record its current state so that it can be restored to that state at a later time. Memento is best suited for externalizing the state of an object when you can't—or don't want to—burden the originator with implementing the storing and restoration of state. In cases where you have to externalize protected data, the design of memento allows you to hide that data from the objects that handle it.

The state pattern allows an object’s implementation to change at run time depending on the internal state of the object. It provides a way to alter the behavior of an object whenever the state of the object changes. To achieve this, the object delegates its behavior to encapsulated state-specific objects.

The strategy pattern abstracts a family of algorithms into individual objects that share a common interface so that they can be used interchangeably. A family of algorithms is a group of calculations that aim to solve the same problem in different ways. Strategy calls for the separate algorithms to be encapsulated in individual objects that conform to a common interface. The client is bound to the interface, and can be dynamically pointed to use any one of the individual strategy objects.

Part 4: Creational Patterns
The last part of our catalog deals with creational patterns, which are used when creating objects. Since Visual Basic is a high-level language, there are not too many choices to be made when creating objects, so there aren’t too many creational patterns that are appropriate for the VB programmer. The final four chapters of the book focus on four that are factory, singleton, builder, and prototype.

The factory pattern provides a mechanism to separate a client from the process of creating a set of related objects or products. It provides an interface to delegate the creation of objects without specifying the concrete class. The factory encapsulates the rules for instantiating objects and buffers the client from the knowledge of the concrete class being instantiated.

The singleton pattern ensures that only one instance of a class exists at any time. It forces client applications to work with only one instance of a class and will not allow these applications to instantiate more than one instance. It provides a single, global point of access for clients to work with a resource.

The builder pattern provides a mechanism for building objects that allows the same interface to build different types of objects. Builder does this by separating the interface that builds the object from its implementation. This allows you to modify the implementation of a builder without breaking existing clients, and to easily add implementations that will be compatible with existing clients.

The prototype pattern provides a method to create objects by cloning pre-exisisting objects. It allows clients to create new objects, not by instantiating the object, but by asking another object—the prototype—to clone itself. By using the prototype pattern, you can internalize the instantiation and initialization of new objects into the class itself.

Appendices
Finally, we have provided three appendices at the end of the book.

Appendix A, “Recommended Books,” provides a list of other books you may find useful. There is a list of books about design patterns for programming, a book on design patterns in architecture, and another list of books on UML. These lists are in no way exhaustive, but each book mentioned here rates at least four out of five stars in our personal listing, and we feel that each will be helpful in furthering your education on these topics.

Appendix B, “Recommended Web Sites,” provides a list of Web sites that have interesting information on design patterns. There is an inexhaustible supply of information on the Web about patterns, and these sites will help you become familiar with this rich resource. In fact, each of these sites has links to dozens of others. We have attempted to provide a brief description of the site in the appendix in order to give you a place to start.

Appendix C, “List of Patterns,” provides an overview of all of the design patterns listed in this book. You should use these to help you when you begin a search for a solution to a design problem. Use this appendix to get a best guess as to an appropriate pattern, and then go to the chapter on the specific pattern for more information, as well as a list of other patterns that may fit the bill.

About the Web Site
This book’s Web site contains working versions of all of the code that is in the book. Whereas in the book we only showed the pieces of the code that demonstrated the pattern, on the Web site you can download the entire set of working code. Over time, as new versions of Visual Basic are released, the Web site will be enhanced with other code samples, new articles on patterns, and updates.

You can link to the code for this book on the Sybex Web site (www.sybex.com) and on the Flash Creative Management Web site (www.flashcreative.com).

About the Authors
Yair Alan Griver is a partner and Chief Information Officer at Flash Creative Management, a Hackensack, NJ–based business and technology consulting firm. Flash is a Microsoft Solution Provider and a Microsoft Authorized Technical Education Center.

Alan is responsible for overseeing the development of Flash’s methods and its development frameworks. He has received the “Most Valuable Professional” award from Microsoft for his expertise in applying Microsoft technology to real world applications and for sharing that knowledge with other software developers.

Alan has written articles published in many leading publications, has lectured throughout the world on computer systems and software design, and has written five books on Visual FoxPro and Visual Basic. He can be reached at 201-489-2500 ext. 201 or at alang@flashcreative.com.

Matthew Arnheiter is a senior consultant for Flash Creative Management. He was a contributing author on MCSD Test Success: Visual Basic 6 and Distributed Applications (Sybex, 1999). He is also a monthly columnist for Component Advisor magazine. Matthew specializes in designing and building enterprise database and collaborative solutions. He can be reached at 201-489-2500 ext. 213 or matta@flashcreative.com.

Michael Gellis is a senior consultant at Flash Creative Management. He is responsible for Visual Basic and Internet-related software development. He coauthored MCSD Test Success: Visual Basic 6 Distributed Applications (Sybex, 1999).

He has also been published in several popular software development magazines. Michael has spoken at Microsoft's TechEd conference on the topic of Visual Basic and Design Patterns. He can be reached at 201-489-2500 ext. 276 or mikeg@flashcreative.com.

About Flash Creative Management
Flash Creative Management works with businesses to jointly map their strategies and to build the supporting processes and technology needed to achieve growth and profit objectives.

Flash Creative Management accomplishes this by supporting an exemplary professional and learning culture that attracts leading IT and strategic planning professionals and helps them develop their skills. Flash professionals have expertise in technology development, strategic planning, and process redesign.

Flash business projects have included aiding companies in strategic and tactical operational planning, planning of companies’ Internet, intranet, and extranet strategies, providing project management expertise to a client’s internal IT group, and redesigning the process for creating and selling new software products for a Fortune 500 company.

Flash’s IT projects have included developing complete Web-based applications, which use component-based architectures based on VB and VFP, as well as SQL Server and Microsoft Site Server/E-Commerce Edition.

Flash’s speaking engagements have included the W3C’s European conference on XML and the Enterprise, Windows 2000 Connections, SQL Connections 2000, and Tech Ed.

To combine the needs of business with technology, Flash’s team members are not only Microsoft Certified Professionals and Solution Developers, but also have an extensive set of project management skills.

Flash Creative Management’s team members have written numerous journal articles and books about business strategy, Web site management, compensation planning, and the design and development of applications. Some of the books written by Flash Creative consultants include the following:

• MCSD Test Success: Visual Basic 6 Distributed Applications (Sybex, 1999)
• Windows NT Workstation 4 Unleashed (Sams, 1996)
• The Visual FoxPro Codebook (Sybex, 1995)
• The FoxPro 2.6 Codebook (Sybex, 1994)
• The FoxPro Codebook (Business One/Irwin, 1992)
For more information about our services, or to read some of the articles mentioned in the authors’ bios, please visit Flash Creative’s Web site at www.flashcreative.com.

...全文
580 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
dbbdggdbbdgg 2001-03-13
  • 打赏
  • 举报
回复
我也推荐一本关于VB.net和Design Patterns的书,下载地址
“中国UML播种机”的“模式”栏目
http://www.umlchina.com/Pattern/Newindex1.htm
http://www.umlforum.com/zippdf/vbpatsall.zip

686

社区成员

发帖
与我相关
我的任务
社区描述
提出问题
其他 技术论坛(原bbs)
社区管理员
  • community_281
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧