This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
INDEX
367
2
45
9
2222222222
44
Symbols+, addition operator, 18\\, backslash character, 15\b, backspace character, 15&, bitwise AND, 18^, bitwise exclusive OR, 18|, bitwise OR, 18\r, carriage return, 15--, decrement operator, 18, 19/, division operator, 18\", double quote, 15\f, form feed, 15>, greater than operator, 21>=, greater than or equal to operator, 21++, increment operator, 18, 19==, is equal to operator, 21!=, is not equal to operator, 21<<n, left shift n places, 18<, less than operator, 21<=, less than or equal to operator, 21&&, logical AND, 21||, logical OR, 21%, modulo, 18*, multiplication operator, 18\n, newline feed, 15
\0, null character, 15>>n, right shift n places, 18\', single quote, 15-, subtraction operator, 18\t, tab character, 15
AAbsolute zero, and Kelvin scale, 47Abstract classes, 7, 76–80, 192Abstract class system, and drawing rectangle
and circle, 78AbstractEmployee class, 181
Employee and Boss derived from, 184AbstractEmployee interface, 182AbstractEmployee subclasses, 187AbstractExpression object, in Interpreter
and Bridge pattern, 169and class adapter, 164–166making an adapter, 159–160moving data between lists, 157–158moving the DataGrid, 160–164object versus class adapters in C#, 166pluggable adapters, 166Proxy pattern, 237two-way adapters, 166
29022 06 pp. 367-394 r5ss.ps 8/21/02 4:55 PM Page 368
BBackslash character (\\), 15Backspace character (\b), 15 Bar charts, 338, 345Bar graph, and Strategy pattern, 343BarGraph strategy, 344BarPlot class, 345
LinePlot class derived from, 342Bar plots, making, 341–342BarPlotStrategy class, 340, 341BarPlot window, 341Base classes, and Template method, 345, 349,
29022 06 pp. 367-394 r5ss.ps 8/21/02 4:55 PM Page 369
bVacationVisitor class, 358, 359byte object, 31
CC, 11, 313
arrays in line with style used in, 87differences between C# and, 26
C#, 1, 25. See also Writing Windows C#programs
application building, 31–32arithmetic and assignment statements
combined in, 18–19arithmetic operators in, 17character constants in, 14–15classes used in, 43class module created from IDE of, 45cloning in, 142commas in for loop statements in, 25–26comments in, 23common Exception classes in, 91comparison operators in, 20–21conditions combined in, 21converting between numbers and strings
in, 13–14and database structure, 203decision making in, 19–20declaring multiple variables in, 14differences between C and, 26differences between Java and, 27do-while statement in, 24flyweight uses in, 231for loop in, 24–25IEnumerator interface in, 284increment and decrement operators in, 18logical operators in, 18looping statements in, 24as managed language, 30most common mistake in, 21–22multiple equal signs for initialization in, 16numeric constants in, 14object versus class adapters in, 166
plots drawn in, 341programming style in, 58project files, 86proxies in, 236simple program in, 16–17States implementing common interface in,
336switch statement in, 22syntax of, 11–27ternary operator, 23variables in, 15–16while loop in, 24
C++, 7, 11, 284, 313arrays in line with style used in, 87C# roots in, 29friend construction in, 302
Caching results, and Composite pattern, 189Capital class, 60Capitalization, 27Caretaker class, 304, 307, 311Caretaker object, and Memento pattern, 302Carriage return (\r), 15 Cascading notifications, 318Case sensitivity, with C#, 11Casting, 13Catch blocks, and multiple exceptions, 91–92catch statement, and exceptions, 90Celsius temperature scale, 43
absolute zero on, 47CEO Employee, 184Chain class, 244, 248, 253Chain interface, 248, 253Chain of responsibility pattern, 8, 239,
241–253, 280applicability of, 242chain or tree?, 251–252class diagram for help system, 251and Command pattern, 255examples in C#, 252–253Help chain, 241implementation of as linear chain, 252
370 Index
67
67
67
67
29022 06 pp. 367-394 r5ss.ps 8/21/02 4:55 PM Page 370
implementation of as tree structure, 251kinds of requests with, 252ListBoxes, 246–248programming a Help system, 248–251program on the CD-ROM, 253purpose of, 253sample code, 243–246simple Chain of Responsibility, 242and syntax tree, 278visual command interpreter program
and design patterns, 7fetching iterators in, 285–286in Filtered enumeration, 288and flyweights, 224for format and value conversion, 48–51interaction between for simple drawing
program, 322isolation of, with Abstract Factory, 120and Mediator pattern, 291as objects, 53–54and properties, 56–58for tables in Façade pattern, 213–215tangled web of interactions between, in
Mediator pattern visual interface, 293traversing series of, 362uses for, 43visiting, 357–358
Class instances, cloning, 142Class libraries, and visitors, 355Class methods, declaring as public, private,
Design Patterns: Elements of ReusableSoftware (Gamma, et al.), 4, 6, 7, 16,133, 179, 192, 197, 198, 223, 283, 302
and Context class, 323and State pattern, 321Template Method discussed in, 347on Templates, 351types of iterators described by, 290Visitor pattern discussed in, 362
Façade pattern, 155, 199–221, 232, 238ADO.NET database connections in, 9and building Façade classes, 207–209building Price table, 215–218consequences of, 220creating classes for each table with,
213–215and Decorator pattern, 198elements in constitution of, 220final application with, 219grocery program using, 209loading database tables, 218–219and making ADO.Net Façade, 209–213program on the CD-ROM, 221
behavior of, 323, 324FillDataSet method, 204FillState class, 325, 330–331, 336Fill State object, 330–331Filtered enumeration, classes used in, 288Filtered iterators, 286–287FilteredIterator class, 286–287Filtered Iterator demo, simple program-
illustrated filtered enumeration, 288
FinalImage class, 235FirstFirst class, 100First normal form (1NF), tables in, 200fixText method, 60, 61Floating point numbers, 13Float variable, methods for, 29FlyCanvas class, 228Flyweight demo, 224Flyweight display, with one folder selected,
225
376 Index
67
67
67
67
29022 06 pp. 367-394 r5ss.ps 8/21/02 4:55 PM Page 376
29022 06 pp. 367-394 r5ss.ps 8/21/02 4:55 PM Page 377
getValue method, 215getWindow method, with Investment
Tracker, 130gif files, and Buttons, 37Global points of access, to Singletons, 126“God class,” Mediator as, 298, 335GoF patterns, 99Grand, 81Graphical editor, state of, 321Graphics, in C#, 66–67Graphics object, 68Greater than operator ((>), 21 Greater than or equal to operator (>=), 21 Green radio button, in watching colors
change program, 314Grid adapter, 166GridAdapter class, 161Grocery Database, Price table in, 216Grocery pricing data, 207, 208Grocery program, using Façade pattern, 209Group class, derived from Address class, 129GUI, 4Guillamets, 84
HHashtable, 89, 290, 309, 327
of color objects, 245kids clubs in, 288–289using, 213in watching colors change program, 316
Hello form, 65Help chain, simple demonstration, 248Help command, receiving, 250–251Help system, programming, 248–251HiTextBox, instance of on Windows
Designer pane of new form, 74HiTextBox control, 74
new derived and regular TextBox control,75
HitTest object, 162“Hollywood Principle,” and Templates, 351
Hook methods, 347, 352Hysteresis, 263
IIBM DB/2, 202ICloneable interface, 149
implemented by SwimData class, 146IComparable interface, 147, 173Icon class, 235Icon files, and Buttons, 37Icons
adding to toolbox, 257and Flyweight, 223Flyweight pattern, 224, 225
IDE. See Integrated developmentenvironment
IdictionaryEnumerator, 289IEnumerator, 181
interface, 284if clause, 19if-else case statements, 321if statement, 19If tests, 322if-then-else, 19Illegal filenames, exceptions for, 94ImageChain class, 245Image class, 235Image control, 234Image proxy, 234ImageProxy class, 234Imager class, 248Imager interface, 234, 235Imager object, 234Images, on Buttons, 37Implementing the interface, 76Implementor
in Bridge pattern, 169VisList interface defines interface of, 173
#include directive, in C and C++, 16Increment operator (++), 18, 19 Indenting, 19, 20
378 Index
67
67
67
67
29022 06 pp. 367-394 r5ss.ps 8/21/02 4:55 PM Page 378
Indexers, 26, 27, 61–62in databases, 199demo of bits gotten from number with, 62
Inheritance, 1, 7, 8, 27, 65–80, 74, 80abstract classes, 76–78and adapters, 157constructors, 65–66drawing and graphics in C#, 66–67interfaces, 76interfaces and abstract classes compared,
79–80namespaces, 68–71object, 5and overloading, 71–72overriding methods in derived classes,
72–73overriding Windows controls, 74–75relationships in Builder pattern, 138replacing methods using new keyword, 74representation of, in UML diagram, 83and UML diagrams, 82–83using, 68virtual and override keywords, 72
Initialization, 56and constructor methods, 65multiple equal signs for, 16
applicability of, 269–270and Chain of Responsibility pattern, 253consequences of, 281–282implementing, 277–280interpreting the language, 271–272motivation for, 269names for participating objects in, 277objects used in parsing, 272–276operation of on simple command in text
field, 281program on the CD-ROM, 282reducing the parsed stack, 276–277simple parsing hierarchy for, 273simple report example, 270–271and syntax tree, 278–280
Language symbols, parsing into tokens, 271LastFirst class, 101Layout, in Decorator, 194Layout managers, 27Leaves, 179, 180, 185, 189Left shift n places (<< n), 18 length property, for arrays, 87Less than operator (<), 21 Less than or equal to operator (<=), 21 Licensing fees, and embedding of commercial
class adapter approach to, 165ListboxChoice class, 134–135ListBox class, 59, 76, 159, 169
KidList class derived from, 294MyList derived from, 164–165properties, 38
ListBox controlItems collection in, 135–136plotting data with, 136
ListBoxes, 38, 58List boxes
automatic language generation with, 281food prices loaded into, 218kidclub, 289
Listbox pattern, 9ListBox type, 166
380 Index
67
67
67
67
29022 06 pp. 367-394 r5ss.ps 8/21/02 4:55 PM Page 380
ListBridge class, 171, 173Listeners, 250ListForm observer, 317List interface, stocks with, 131List observer, 317ListObs window, 315Lists, data moved between, 157–158Logical AND operator (&&), 21 Logical Not operator (~), 21 Logical operators, 17, 18Logical Or operator (__), 21 Looping, through arrays, 87Looping statements, 24Lowercase, C# syntax in, 11Lower class, 60
MMacro language, 269Macro record button, 281main function, 17MainMenu control, 257
adding to window form, 39Managed languages, and garbage collection,
30Manager class, 360, 361ManagerVisitor, 361Math computation, factory patterns in,
103–105Mathematica, 270Mediator
and command buttons management, 321
and handling of mouse and paint events,310
interaction between buttons and, 330StateManager and, 326–328, 329
Mediator class, 294, 296–297, 306, 326interactions between classes simplified
with, 293Mediator object, interactions between
Command objects and, 198
Mediator pattern, 8, 239, 291–299, 311consequences of, 298–299example system, 291–292and initialization of system, 297interactions between controls, 292–293looser coupling between classes with, 291mediators and command objects, 297program on the CD-ROM, 299sample code, 294–297simple program with two lists, two
buttons, and text field, 292and single interface mediators, 299
Mediators, and “god class,” 298, 335Memento class, 306, 321Memento interface, and handling undo list,
editing or deleting, 207Row selection, detecting, 162Rumbaugh, James, 81
SSalaries computation, 180–181SalaryType column, data in, 200Scope, 16, 25Scott, K., 81Second normal form (2NF), tables in, 200
Seeding class, 108Seeding diagram, Seeding interface and
derived classes in, 109Select button, 321, 323select case statements, 321SelectedIndex property, 162Selected instance, of Folder, 228, 229SelectIndexChanged event, 295Select method, and Mediator, 295selectOne method, added to State interface,
324Select statement, 204, 205Select tests, 322Self-promotion, and Composite pattern,
186–187Semicolon (;)
C# statements terminating with, 11at end of declaring draw method as
abstract, 77statements terminating with, 17
Sender class, 248sendNotify event, 315, 316sendToChain method, 244, 248Sequential operations, languages and
consequences of, 126and creating instance of the class, 125–126and creating singleton using static method,
123–124exceptions and instances, 124global point of access provided to
singletons, 126and throwing the exception, 125
SlashDecorator, CoolButton decorated with,196
Smalltalk, 7, 284, 302Model-View-Controller framework for, 3
Smalltalk Companion. See Design PatternsSmalltalk Companion
SORT, 273SortBridge class, 173
sorted list generated using, 175SortedList class, 89–90Sort object, 273Special characters, representations of, 15Split method, of String class, 51Spooler class, 123, 124SQL. See Structured Query LanguageSQL query, and ADO.NET Façade, 209, 211SQL-92 standard, 202Square, creating from rectangle, 69–71Square class, deriving from Rectangle class,
69–70, 71Stack class, 271
Stack object, 90Stack reduction, and syntax tree, 278Stacks, 271
ParseObject pushed onto, 272reducing during parsing, 276
State, of graphical editor, 321State interface, selectOne method added to,
324StateManager, 326–328
and the Mediator, 329StateManager class, 323
current state tracked by, 324and switches between states, 325–326
State object, mouse activities handled by,323, 324
State pattern, 8, 239, 309, 321–336consequences of, 335–336Fill state handled with, 330–331and Mediator interaction with State
Manager, 326–329Mediators and “god class,” 335program on the CD-ROM, 336sample code, 321–325simple drawing program illustrating, 322and state transitions, 336and Strategy pattern, 337and switching between states, 325–326undo list handled with, 331–333using, 321VisRectangle and VisCircle classes,
333–335State transitions, and State pattern, 336Static methods
in File object, 92and global point of access, 126singleton created with, 123–124
Static variable, 123StockFactory class, 132–133Stocks, with list interface, 131Stocks:Equities class, 132
Index 387
2
4
2222222222
444
29022 06 pp. 367-394 r5ss.ps 8/21/02 4:55 PM Page 387
Store class, derived from DBTable, 213StoreFoodPrice objects, and Prices class, 215StoreKey, Stores table with, 207StoreName, Stores table with, 207Stores table, 207, 214, 218Straight seeding
consequences of, 344and Context class, 339and drawing plots in C#, 341–342line and bar graph strategies, 340motivation, 337–338program commands, 339–340program on the CD-ROM, 344sample code, 338simple panel to call different plots, 340UML diagram of, 343
version of, 56switch statement, 22, 27Sybase, 202Symbols, in UML diagrams, 82Syntax tree, and parsing of stack, 278–280System.Collections namespace, 88System.Drawing namespace, 68, 229System namespaces, 17, 31, 68
TTab character (\t), 15 Tables, 199, 203, 231
classes for in Façade pattern, 213–215deleting contents of, in ADO.Net,
205–206employee names and salary type, 200
388 Index
67
67
67
67
29022 06 pp. 367-394 r5ss.ps 8/21/02 4:55 PM Page 388
Temperature classbuilding, 45–47decisions put into, 47–48
Temperature conversion program, simple,43–45
Template class, methods in, 347Template Method pattern, 239, 345–352
consequences of, 352kinds of methods in Template class, 347motivation, 345–347programs on the CD-ROM, 352sample code, 347–350templates and callbacks and, 351–352Triangle drawing program, 350–351
Template methods, 347Template pattern
and abstract Triangle class, 348using, 345
Templates, 345temp variable, 47TerminalExpression, 280TerminalExpression object, in Interpreter
pattern, 277Ternary operator, 23Testing, for end of file, 94–95Text, and changes in label, 40TextBox class, 33, 36, 74TextBox control, 74
and new derived HiTextBox control, 75TextBoxes, 189TextBox properties, 37Text comments, in UML diagrams, 85Text data, and different line-breaking
strategies, 338Text files
reading, 93writing, 93–94
Text property, 36Third normal form (3NF), tables in, 200, 201Third-party products, VBA embedded in, 269Throwing exceptions, 92
throws keyword, 27Throw statement, 92TimedFinalEvent class, 108, 109, 110, 112Time entry interface, with parsing of symbols
and Boss visits, 359catch-all operations with visitors,
360–361consequences of, 362and double dispatching, 361motivation, 353–355program on the CD-ROM, 363sample code, 355–356times to use, 355traversing series of classes and, 362using, 353vacation visits demo, 360visit and accept methods interactions, 354
visiting several classes, 357–358visiting the classes, 357
decorating inner class in, 197grid table with, 160Integrated Development Environment, 65namespaces, 68screen from, showing properties interface,
176, 177visual builder in, 44
Vlissides, J., 361
WWealthBuilder class, 135WealthBuilder program, with list of equities,
list box, check boxes, and plot panel, 137
Web sites, for learning design patterns, 7While loop, 24White space characters, 14
representations of, 15
Index 391
2
4
2222222222
444
29022 06 pp. 367-394 r5ss.ps 8/21/02 4:55 PM Page 391
Wider data types, and narrower data types,13
Windowsand data display, 313and ODBC, 203
Windows controls, 35–40, 80Buttons, 37CheckBox, 36–37Items collection, 38–39labels, 35ListBoxes and ComboBoxes, 38menus, 39overriding, 74–75radio buttons, 37selection of basic, 35TextBox, 36ToolTips, 39–40
Windows Controls program, 40–41Windows Designer, 74
in Visual Studio.NET, 32
Windows Form class, 35Windows Form Designer, 230Windows.Forms library, 33WithClass UML diagrams, 86writeLine function, 17writeLine method, 96Writing text files, 93–94Writing Windows C# programs, 29–41
building a C# application, 31–32classes and namespaces in C#, 30–31managed languages and garbage collection,
30objects in C#, 29simplest Window program in C#, 32–34Windows controls, 35–40Windows controls program, 40–41
XXFactory class, 100XML, and ADO.NET, 203
392 Index
67
67
67
67
29022 06 pp. 367-394 r5ss.ps 8/21/02 4:55 PM Page 392