This content was uploaded by our users and we assume good faith they have the permission to share this book. If you own the copyright to this book and it is wrongfully on our website, we offer a simple DMCA procedure to remove your content from our site. Start by pressing the button below!
tag. The same applies to list tags and header tags. There isn't too much more to this. You might want to pull out the document titles as you go along, but that's about all." "And how do I go about this? It still seems like a lot of work," Herb protested. "I'd use the Interpreter pattern," Sandy answered. "Its advantage is that every item that you need to interpret is handled in a separate class, and none of them is very complicated." "And I'll bet I can guess how you connect these little Interpreter objects," Herb replied. "Another Chain of Responsibility. This really simplifies my work." Then his face fell. "I just remembered. Some of the documents are going to be in XML. That's just enough to throw the whole design for a loop." "Not really," Sandy pointed out. "You could use the Strategy pattern to select an HTML or XML parser as the first step in the chain. That's not hard at all, and there are lots of Java-based XML parsers available."
"Terrific!" said Herb. "I hope the rest of the project is as easy as this is turning out to be." "Here," said Sandy, "why don't you borrow my copy of Design Patterns until the copy you're going to order comes in."
Chapter 36. Mary's Dilemma Herb finished his Chain of Responsibility development and made the framework available for the rest of his project group. One of his first users was Mary, who suddenly discovered that she had a number of additional requirements that Herb's chain did not fulfill. She wanted to be able to produce summaries of each document. "For example," she told Sandy, "I need to keep sentence numbers and word numbers of every term that we find in a document. Herb has that information, but he doesn't store it anywhere." "Why don't you subclass Herb's classes and store the data in whichever class you need it?" asked Sandy. "I don't know what else I'll need until Ifinish developing the algorithms, and I don't want to take a chance that I'll mess up Herb's part so that he can't fix it if we need to make basic changes," Mary explained. "Let me see," said Sandy, reaching for the Design Patterns. "I think there is a pattern that just suits your situation. Yes, here it is: the Visitor." "Sounds like D rrenmatt," said Mary, ever the German scholar. "What does it do?" "The idea is very simple," Sandy explained. "You write a class that visits the target class and retrieve information from it." "And how do I visit a class that I didn't write?" Mary asked. "That's just the situation that the Visitor is for," said Sandy. "You subclass the classes that you're going to visit and put an accept method in them. Then the Visitor calls each one and returns a reference to the Visitor so that you can operate on all the public methods and package-protected data in the class. You get what you want, and the original classes are unchanged." "That's great!" said Mary. "It's like auditing the classes without paying tuition. That's the pattern for me."
Bibliography Alexander Christopher S. Ishikawa A Pattern Language. New York: Oxford University Press, 1977. Alpert Sherman K. Brown B. Woolf The Design Patterns Smalltalk Companion. Reading, Mass.: Addison-Wesley, 1998. Arnold Ken J. Gosling The Java Programming Language. Reading, Mass.: Addison-Wesley, 1998. Booch Grady J. Rumbaugh I. Jacobson The Unified Modeling Language User Guide. Reading, Mass.: Addison-Wesley, 1999. Buschman Frank R. Meunier Pattern Oriented Software Architecture: A System of Patterns. New York: John Wiley and Sons, 1996. Cooper James W. Principles of Object-Oriented Programming in Java 1.1. Research Triangle Park, N.C.: Ventana Press, 1997. Cooper James W. Byrd Roy J. "Lexical Navigation: Visually Prompted Query Refinement" , presented at Digital Libraries 1997, Philadelphia, Pa. Cooper James W. Neff Mary R. "ASHRAM—Active Markup and Summarization," presented at the Hawaii International Conference of Systems Sciences, Maui, Hawaii, January, 1999. Coplien James O. Advanced C++ Programming Styles and Idioms. Reading, Mass.: AddisonWesley, 1992. Coplien James O. D. Schmidt Pattern Languages of Program Design. Reading, Mass.: AddisonWesley, 1995. Fowler Martin K. Scott UML Distilled: Applying the Standard Object Modeling Language. Reading, Mass.: Addison-Wesley, 1997. Gamma Erich R. Helm R. Johnson J. Vlissides Design Patterns: Abstraction and Reuse of Object Oriented-Design. Proceedings of ECOOP, Kaiserslautern, Germany, 1993: pp. 405–431. Gamma Erich R. Helm R. Johnson J. Vlissides Design Patterns: Elements of Reusable ObjectOriented Software. Reading, Mass.: Addison-Wesley, 1995. Grand Mark Patterns in Java. Vol. 1. New York: John Wiley and Sons, 1998. Krasner G. E. S. T. Pope "A Cookbook for Using the Model-View-Controller User Interface Paradigm in Smalltalk-80" . Journal of Object-Oriented Programming I(3), (1988). Kurata Deborah "Programming with Objects" . Visual Basic Programmer's Journal (June 1998) pp. 91–94. Pree Wolfgang Design Patterns for Object-Oriented Software Development. Reading, Mass.: Addison-Wesley, 1994. Riel Arthur J. Object-Oriented Design Heuristics. Reading, Mass.: Addison-Wesley, 1996.
Vlissides John Pattern Hatching: Design Patterns Applied. Reading, Mass.: Addison-Wesley, 1998.