index [ptgmedia.pearsoncmg.com]ptgmedia.pearsoncmg.com/images/0201844532/index/cooperindex.… ·...
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
pattern, 277Abstract Factory pattern, 9, 97, 115–121,
154and Builder pattern, 138consequences of, 120and GardenMaker factory, 115–120more classes added to, 120
Abstraction, in Bridge pattern, 169abstract keyword, 82
Note: Italicized page locators refer to figures/tables.
29022 06 pp. 367-394 r5ss.ps 8/21/02 4:55 PM Page 367
Acceptance, and learning design patterns, 6accept method, 354, 356, 358, 361
adding to subclasses, 355Accessor methods, 45Action methods, 299ActionVerb class, 280ActiveX controls, 176ActiveX Data Objects, 203Adapter class, 318Adapter pattern, 9, 155, 157–167, 237
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
Adapters, 157decorators, composites and, 197–198making, 159–160
Addition operator (+), 18Address class, Person and Group derived
from, 129addToChain method, 244Add2.cs program, 16–17ADO DataSet manipulation, and Clone
method, 142ADO.NET, 199, 203
connecting to database in, 204deleting contents of table in, 205–206executing query in, 205reading data from database table in,
204–205rows added to database tables with,
206–207using, 203–207
ADO.NET database connectionsas proxies, 236in Façade pattern, 9
ADO.NET FaçadeDBTable class, 211–213making, 209–213
AgeSwimData class, 151age distribution display for, 150
Aggregation (in UML diagrams), diamondsindicating, 84
Algebraic strings, parsing, 270Algorithms
and Strategy pattern, 337Strategy pattern and dynamic selection of,
344and Template pattern, 345
AND operation, 17Annotation, and UML diagrams, 85–86AnnualGarden class, 117ANSI standards, and SQL, 202Appearance property, in CheckBoxes, 36Application class, 31Approach, 202Arithmetic operators, 17, 18Arithmetic statements, combining assignment
statements and, 18–19Array class, 31ArrayList, 38, 290, 361
of child nodes, 180Kid objects in, 284Observer objects added to, 314and Prototype pattern, 147and Stack class, 271StoreFoodPrice objects in, 215and TriangleForm class, 350
ArrayList methods, 88, 89ArrayList object, 54, 88Arrays, in C#, 87–88Arrow-object state, 336Assignment statements, combining arithmetic
statements and, 18–19Autohighlight feature, of C# TextBox, 75Automobile factories, 115AxsDatabase class, 210
368 Index
67
67
67
67
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,
352Behavioral patterns, 6, 97, 239–363
Chain of Responsibility, 241–253Command, 255–268Interpreter, 269–282Iterator, 283–290Mediator, 291–299Memento, 301–312Observer, 313–319State, 321–336Strategy, 337–344Template Method, 345–352Visitor, 353–363
Bitfields, 26BitList class, 61Bitmap class, 235Bitmaps, 231Bitwise And (&), 18 Bitwise exclusive Or (^), 18 Bitwise operators, 17Bitwise Or (_), 18 BlueCommand class, 265
derived from ColorCommand class, 267BlueCommand object, and isUndo method,
265Blue radio button, in watching colors change
program, 314bmp files, and Buttons, 37Bonds, with check box interface, 131
Booch, Grady, 81Boolean operators, 17Boolean variables, 13Boolean variable type, spelling in C#, 27bool object, 31Borland Paradox, 202Boss class, 183–184, 187, 357, 358
derived from AbstractEmployee class, 184visitor classes visiting, 359
BossVisitor, 361Braces ({}), 70
classes/functions surrounded by, 17indentation styles for, 20statements in condition enclosed within, 19
break statement, 22, 27Bridge pattern, 9, 155, 169–177, 237
consequences of, 177extending the bridge, 173–176UML diagram for, 173VisList classes, 172Windows forms as bridges, 176
Bridger class, 173Bridger interface, defined, 170btClone_Click event, 149btConvert_click method, 44Builder pattern, 76, 98, 107, 129–139, 154
consequences of, 138inheritance relationships in, 138Investment Tracker, 130–135and Prototype pattern, 141using Items collection in ListBox control,
135–137Builder program, 176Builder tools, 176Butterfly class, 104Button class, 256, 257, 260, 294, 339Button events, handling, 119Buttons, 37, 58, 189, 255, 256
decorating, 191ToolTip over, 40
Button value, 36
Index 369
2
4
2222222222
444
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
sample, 243Chain of Responsibility program, class
structure of, 247Character constants, 14–15CheckBox, 36–37Check Box Builder, 133Check boxes, 189, 255Check box interface, bonds with, 131CheckChoice class, 133–134Checked property, of radio buttons, 37Child nodes, ArrayList of, 180Children, and nodes, 179Circle button, 321, 323Circle class, 77CircleSeeding, 111
instance of, returned by PrelimEvent class,110
subclass, 108, 109Circle seeding
of 100 Free, 112of swimmers, 107
Circle state object, 324Class adapter, 157, 164–166
list adapter approach to, 165object adapter versus, 166
Class-based Adapter, 169Class containment, 55Classes, 1, 17, 63
abstract, 76–78in C#, 30–31cloning, 145, 146–147
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,
and protected, 71Class modules, 45Class patterns, object patterns versus, 155Clear button, 291, 294, 297, 302, 321
behavior of, 323Command objects for, 309
Clear method, and Mediator, 295Click events, event handler for, 295Client object, in Interpreter pattern, 277cloneMe method, inheritance of by
AgeSwimData class, 150Clone method, 142, 146, 149Cloning
in C#, 142classes, 145, 146–147and Prototype pattern, 141, 153
closeTriangle method, 352CLR. See Common language runtimeCocoon class, 105Colleague, and Mediator, 293Colleague elements, 299
Index 371
2
4
2222222222
444
29022 06 pp. 367-394 r5ss.ps 8/21/02 4:55 PM Page 371
Collection objects, 88–90Collisions, avoiding, 68ColObserver class, 315–316, 318Colon (:), 70
and parsing, 49ColorChain class, 245Color-changing code, in Windows Controls
programColorCommand class, 265–266
classes derived from, 267ColorForm observer, 316ColorImage class, 248Color objects, 316Color observer, 317Colors, watching changes in, 314–317Columns, 199, 203ComboBox properties, 38ComdToolBarButton class, 327–328Command buttons, 297
automatic language generation with, 281CommandHolder approach, UML diagram
of, 262CommandHolder interface, 259–262Command interface, 294, 309, 339
ExitCommand implementing, 84implementing in new classes, 257and Undo function, 263and unDo method, 265
CommandMenu class, 260Command objects, 256–257, 259, 261, 277
building, 257–259interactions between Mediator object and,
198Mediators and, 297and Undo command, 264
Command pattern, 8, 239, 255–268, 280,311
and building command objects, 257–259and CommandHolder interface, 259–262and command objects, 256–257consequences of, 259
and Mediator pattern, 297menu designer interface, 258menu part of using ComandHolder
interface, 262motivation for, 255–256programs on the CD-ROM, 268purpose of, 256simple program demo, 255undo function provided by, 262–267
Commands, undoing, 263Commas, in for loop statements, 25–26Comments, 17, 23
shown in box with turned-down corner, 86
in UML diagram, 85Commercial languages, licensing fees and
embedding of, 269Common language runtime, 30Communication patterns, 5Company class
with any number of instances ofEmployee, 85
instances of Person and Employee in, 84CompareTo method, 147, 173Comparison operators, 20–21, 21Compilation errors, 22Compiler error messages, 25Complex class, 62Components, ordering, 189Composite pattern, 9, 155, 179–190, 237,
283, 355, 362and Boss class, 183–184building Employee tree, 184–186composites in .NET, 189computing salaries, 180–181consequences of, 188doubly linked lists, 187and Employee class, 181–183implementation of composite, 180other implementation issues with, 189programs on the CD-ROM, 190
372 Index
67
67
67
67
29022 06 pp. 367-394 r5ss.ps 8/21/02 4:55 PM Page 372
and self-promotion, 186–187and simple composite, 188–189
Composites, adapters, decorators and,197–198
Composition, and UML diagrams, 84–85ConcreteImplementors, 173
in Bridge pattern, 169Concrete methods, 347Conditions, combining, 21Console class, 17, 31Constants
character, 14–15numeric, 14
const modifier, in C#, 12Constructor method, for Rectangle class, 68Constructors, 43, 72, 80Containers, 189
for Command object, 259as Decorators, 192
Containment, 5list of swimmers and their times using, 55
contains method, 306Context class, 323, 337, 339Context interface, 344Context object, in Interpreter pattern, 277ControlChain class, 249–250Controller, 4Control names, 58Controls
in C#, 176, 249–250collection, 189interactions between, 292–293Mediator and initialization of, 297
Controls array, and Windows formcontaining buttons, 194
Convert methods, for converting betweennumbers and strings, 13
CoolBar, 192CoolButton, 195
decorating, 191–193decoration of, with SlashDecorator, 196
CoolDecorator, 196Coplien, J. O., 141Copy button, 291Copy method, and Mediator, 295Copy-on-write
objects, 232and Proxy pattern, 237
Count property, 88, 89, 180Coupling between objects, reducing, 253CpyButton class, 294CreateText method, 93Creational patterns, 6, 97–154, 123
Abstract Factory, 115–121Builder, 129–139Factory Method, 107–113Prototype, 141–154Simple Factory, 99–106Singleton, 123–127summary of, 154
csFile class, 95–96, 142csPatterns namespace, 229Current() property, 284currentState variable, 325Cursor class, 235Customer version, of ListBox, 172
DData
extrinsic, 223, 224, 226getting out of databases, 201–202intrinsic, 223, 232moving between lists, 157–158plotting in Builder pattern, 136
Database class, 220Databases
connecting with ADO.Net, 204description of, 199–201getting data out of, 201–202kinds of, 202reading data from with ADO.Net, 204–205structure of, 203
Index 373
2
4
2222222222
444
29022 06 pp. 367-394 r5ss.ps 8/21/02 4:55 PM Page 373
Database tablesloading and Façade pattern, 218–219rows added to using ADO.Net,
206–207DataColumns, 160DataGrid, 9, 40
and row selection detection, 162using, 160–162
DataGrid type, 166Data manipulation, interface manipulation
separated from, 45Data model, 3Data modification, and Iterator pattern,
289–290DataRow, 203, 220DataSet, 142, 203, 220Data streams, 94DataTable class, 160, 161, 203, 220Data types, in C#, 12dBase, 202, 209, 220, 232DBTable, 211–213, 215
classes derived from, 207, 213classes wrapped in by Façade, 220
DB/2 (IBM), 2022Decisions
making in C#, 19–20in Temperature class, 47–48
Declarationproperty, 56multiple variable, 14variable, 15–16, 25
Decorator class, 191Decorator panel, code for button added to,
194Decorator pattern, 155, 191–198, 238
consequences of, 198decorating CoolButton, 191–193decorators, adapters, composites and, 198and event handling, 193–194and multiple decorators, 195–196and nonvisual decorators, 197
programs on the CD-ROM, 198and Proxy pattern, 237
Decrement operator (--), 18, 19 Deep copy, 147Default case, for switch statements, 22Delegates, 26, 27, 59–61
demo, 59Delete * from Table SQL statement, 205Derived classes
caching special cases in, 361overriding methods in, 72–73and Template method, 345, 347, 352
Design patterns, 1C#, 8defining, 5–6description of, 3–4learning, 6–7and object-oriented approaches, 7–8studying, 7
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
Design Patterns Smalltalk Companion, The(Alpert, Brown, and Woolf), 4, 5, 7, 231,251, 269, 302, 307
Diamonds, in UML diagrams, 84Director class, 133Display classes, using Bridge pattern, 169,
170Division operator (/), 18 Dot (.), and Convert methods, 13Double angle brackets, 84Double dispatching, and Visitor pattern, 361Double quote (\"), 15 DoubleRect class(es), 72, 73
374 Index
67
67
67
67
29022 06 pp. 367-394 r5ss.ps 8/21/02 4:55 PM Page 374
double type, 14Double variable, methods for, 29Doubly linked lists, and Composite pattern,
187do-while loop, 24draw code, in base Triangle class, 351drawCommand class, draw method in, 266DrawData objects, 265drawHandle method, 333Drawing, in C#, 66–67Drawing interface
circle and rectangle objects implementing,332
VisRectangle implementing, 333Drawing program, for illustrating State
pattern, 321, 322, 323–325drawLine method, 352drawList collection, 265DrawMemento class, 332draw method, 77, 349, 350, 352
in drawCommand class, 266as empty method, 79for Rectangle class, 68and Visitor class, 354
DrawObject, three subclasses of, 353draw routine, and Triangle class, 348draw2ndLine method, 348, 349, 350, 352
EEditing, and ADO style of programming,
207Equal signs (multiple), for initialization, 16else clause, 19, 20e-mail address book, 129Employee, instances of, in Company, 84Employee class, 181–183, 188
derived from AbstractEmployee class, 184
derived from Person class, 82–83visitor classes visiting, 359and Visitor pattern, 355–356
Employee records, in databases, 200Employee salaries
sorted by magnitude, 201sorted by name, 201
Employee tree, building, 184–186EmployeeVisitor, 361EmpNode class, 185Empty methods, base classes with, 79Encapsulation, 7, 8, 47, 51, 71, 337EndChain class, 250End of file, testing for, 94–95End-of-file function, 94Enumerated types, 27Enumeration class, 287Enumeration interface, 9Enumerator, 182Enumerator property, of Hashtable, 213Equal sign (=), for representing assignment of
data, 17Equities class, 132Error checking, and language introduction,
281Error handling
in C#, 90encapsulation of, 51
ET++, 4Event class, 107–108EventHandler class, 194Event handling in Decorator, 193–194
control size and position, 194layout considerations, 194
Events button, 66Events classes, 109Examplar pattern, 141Examples
FileExit class, 258Flyweight, 224–230simple report, 270–271
Exception classes, in C#, 91Exception errors, 13Exception object, 94
Index 375
2
4
2222222222
444
29022 06 pp. 367-394 r5ss.ps 8/21/02 4:55 PM Page 375
Exceptions, 9in C#, 90–91in file handling, 94and Singleton pattern, 124
Exceptions class, 31Execute command, and Butterfly class, 104Execute method, 259, 260, 280, 295, 328Execute() method, 256ExecuteNonQuery method, 205ExitCommand, Command interface
implemented by, 84ExitMenu class, 257External iterators, internal iterators versus,
290Extrinsic data, 223, 224, 226
FFaçade classes
building, 207–209building price query, 207–208
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
Factory class, 100, 224Factory method pattern, 97, 107–113
Events classes, 109–110and other factories, 112–113Prototype pattern combined with, 152StraightSeeding, 110–111Swimmer class, 109
variations on, 113when to use, 113
Factory pattern(s), 8, 103–105, 129, 154Fahrenheit temperature scale, 43, 44false reserved word, 14, 17Fast Fourier Transform (FFT), 103FFT “butterfly,” 103File compression, with different algorithms,
337FileExit class, 258File handling
in C#, 92–94exceptions in, 94file object, 92–93reading to text file, 93writing to text file, 93–94
FileList box, 246FileList class, 248File object, 92–93Files, opening for reading, 96Fill button, 321
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
FlyweightFactor class, 224Flyweight pattern, 8, 155, 223–232, 238
copy-on write objects, 232discussion about flyweights, 224example code, 224–230flyweight uses in C#, 231handling the mouse and paint events,
230program on the CD-ROM, 232sharable objects, 231–232
Flyweights, generation of, 228Folder class, 226, 228FolderFactory class, 225, 227, 228Folders
dynamic selection of and FolderFactory,227
Flyweight demo, 224Flyweight example and selection of,
229–230selection of one in Flyweight display, 225
Food class, derived from DBTable, 213FoodKey, Foods table with, 207FoodName, Foods table with, 207Foods table, 207, 214, 218foreach looping construct, 24, 88For loop, 24–25For loop statements, commas in, 25–26Format conversion, classes used for, 48–51Format method, 29Form class, 43, 65, 66, 256Form Designer, 258Form feed (\f), 15 Form initialization method, 194, 295Form_Load routine, 247Form object, 259Form1 class, simple hello window in, 65Forms, menus added to, 39Form window, 68, 69Fortran, 19Fowler, M., 81FoxBase, 202
Friend construction (C++), 302ftx delegate, 60
GGamma, Eric, 4“Gang of Four” (GoF), 4, 277Garbage collection, and managed languages,
30Garden class, 116Gardener program
major objects in, 117user interface of, 117
Garden interface, 116GardenMaker factory, 115–120
and handling RadioButton and Buttonevents, 119–120
PictureBox, 118–119Garden object, methods in, 118GardenPic class. from PictureBox, 118Gestalt, 3getBuilder method, 133getChain method, 244getChild method, 186, 188getChild operation, 180getClass method, 100getConvTemp method, 47getEnumerator method, 289getFrname method, 102GetHashCode property, 309getIterator method, 285getJob method, 82, 83getLname method, 102Get property, and Rectangle class, 306getSalaries() method, 181, 184getSeeding method, 109getSelected method, 136getSpooler method, 123, 124getSubordinates method, 283getSwimmers method, 111getVacationDays method, 361getVacDays function, 356
Index 377
2
4
2222222222
444
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
InitializeComponent method, 35, 66, 67init method, 66, 112Instances, 43, 63
of classes, 53and Singleton pattern, 124
Integers, methods for, 29Integrated development environment, class
module created from, 45Interaction, between objects, 5Interface manipulation, data manipulation
separated from, 45Interfaces, 1, 7, 76, 179
abstract classes compared with, 79–80dissimilar classes with same, 150–152For Iterator, 283
and Observers, 314and UML diagrams, 84
Interleaved Commands, 263Internal iterators, external iterators versus,
290Internalization, and learning design patterns,
6internal keyword, 302Internet Explorer, 191InterpChain class, 279Interpreter pattern, 8, 239, 269–282
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
Intrinsic data, 223, 232int type, 14Investment Tracker, 130–135
CheckChoice class, 133–134ListboxChoice class, 134–135StockFactory class, 132–133
is equal to operator (==), 21 isLegal, 275is not equal to operator (!=), 21 Isosceles triangle, drawing, 349–350, 351isUndo method, 265Items collection, 38, 159
methods for, 39using in ListBox control, 135–136
Iterator, fetching, 285–286
Index 379
2
4
2222222222
444
29022 06 pp. 367-394 r5ss.ps 8/21/02 4:55 PM Page 379
Iterator code, sample, 284–285Iterator interface, and KidIterator class, 285Iterator pattern, 9, 239, 283–290
consequences of, 289–290and filtered iterators, 286–288motivation, 283–284programs on the CD-ROM, 290sample iterator code, 284–286and tracking clubs, 288–289
JJacobson, Ivar, 81Java, 11, 302
arrays in line with style used in, 87C# roots in, 29differences between C# and, 27Hashtable, 213
Java Design Patterns: A Tutorial, 4JPEG files, and Buttons, 37
KKelvin temperature scale, converting
to, 47Keyboard listeners, 250KeyDown event, 251KeyDown event listener, 250Keys
and Hashtable, 213to Hashtable of color objects, 245for Price table, 215
Keywords, 43KidClub class, 287KidData class, 284, 287KidIterator class, 285KidList class, 286, 294Kid objects, 284, 285Kids class, 285
LLabel control, properties for, 36Labels, 35, 40
Languagesapplicability of, 270and Interpreter pattern, 269interpreting, 271–272
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
languages, 269LineButton command Button class, 339–340Line graphs, 338
plotting, 345and Strategy pattern, 343
LineGraph strategy, 344LinePlot class, 345Line plots, making, 342LinePlotStrategy class, 340, 341LinePlot window, 341List adapter, 158, 159
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,
331Memento objects, 302, 307, 308Memento pattern, 8, 239, 301–312,
327, 331cautionary note about sample code with,
308–309and command objects in user interface,
309–310consequences of, 311implementation, 302motivation, 301–302mouse and paint events handled
with, 310program on the CD-ROM, 312purpose of, 301rectangles drawing pattern demo, 302,
303, 304roles for objects defined by, 302sample code, 302–309UML diagram for drawing program with,
311MenuBar, 257MenuItem class, 257, 260Menu items, 255, 256Menus adding to form, 39Metafile class, 235
Index 381
2
4
2222222222
444
29022 06 pp. 367-394 r5ss.ps 8/21/02 4:55 PM Page 381
Methods, 43, 45accessor, 45ArrayList, 88, 89Concrete, 347with Garden object, 118Hook, 347, 352implementations of and interfaces, 76for Items Collection, 39for objects, 29overriding in derived classes, 72–73polymorphic, 72replacing using new, 74Template, 347in Template class, 347virtual, 347
MicroGold, 86Microsoft Access, 202Microsoft Excel, 313Microsoft Office products, VBA in, 269Microsoft SQL Server, 202Microsoft Works, 202Model-View-Controller framework,
3, 4Modules, class, 45Modulo operator (%), 18 Mouse, handling in C#, 230Mouse click events, 323MouseDown event, 162
and State object, 323, 324Mouse drag events, 323MouseEventHandler, 162, 193MouseMove, 192, 230, 252MouseUp event, 322move method, 333moveNext() method, 287MultiChoice interface, 132
with Investment Tracker, 130Multiple exceptions, 91–92Multiple variables, declaring, 14Multiplication operator (*), 18 MultVar class, 276
MultVar object, 280MyList class, derived from ListBox class,
164–165
NNameFactory, 102Namer class, 100, 101Namer Factory program, 102Namer program, execution of, 103Namespaces, 30–31, 68–70Narrower data types, and wider data types,
13.NET
composites in, 189Visual control, 176
Netscape Navigator, 191new keyword, methods replaced using, 74Newline (line feed) character (\n), 15new operator, 97New Project selection window, 31nextToken method, 52nextTop method, 271NoCmd Chain element, 246NoCmd class, 248Node object class, 189Nodes, 179, 180, 185, 189NonTerminal Expression, 280NonTerminalExpression object, in Interpreter
pattern, 277Nonvisual decorators, 197Normal form, 200Notification messages, and Observer pattern,
318NOT operation, 17Null character (\0), 15 Null exceptions, 94null reserved word, 14Numbers, converting between strings and,
13–14Numerical types, conversion from, 29Numeric constants, 14
382 Index
67
67
67
67
29022 06 pp. 367-394 r5ss.ps 8/21/02 4:55 PM Page 382
OObject adapters, 157
class adapters versus, 166Object Database Connectivity, 202–203Object-oriented approaches, notes on,
7–8Object-oriented languages, and
signatures, 71Object-oriented programming, 1, 8
and design patterns, 4difference between procedural
programming and, 53factory concept in, 107template patterns in, 352
Object patterns, class patterns versus, 155Objects, 1, 43
in C#, 29and Chain of Responsibility pattern, 242classes as, 53–54composition of, 8, 157and creational patterns, 97interaction between, 5saving state of, 302used in parsing, 272–276
Objects class, 31object type, objects fetched from ArrayList
and, 88Observer interface, 315Observer pattern, 239, 242, 299, 313–319
candidate for, 317consequences of, 318–319data displayed as list and in graphical
mode, 313and message to the media, 318program on the CD-ROM, 319simple control panel to create red, green,
or blue “data,” 314UML diagram of observer interface
and subject interface implementationof, 317
and watching colors change, 314–317
Observersnotification messages sent to, 318and Observer pattern, 314update methods to, 319in watching colors change program, 315,
316, 317ODBC. See Object Database ConnectivityOleDbAdapter, 220OleDbCommandBuilder, 220OleDbCommand class, 203OleDbCommand object, 205OleDbConnection, 220OleDbConnection object, 203OleDbDataAdapter, 203One’s complement (~), 18 OneSexSwimData class, displaying with one
sex on the right, 148OpenCommand class, 261OpenForRead statement, 95OpenForWrite() method, 96OpenForWrite statement, 95OpenMenu class, 257open method, 204Operator overloading, 27, 62Oracle, 202Ordering components, and Composite
pattern, 189Organizational chart, typical, 180Origin, 270Originator class, 311Originator object, and Memento pattern, 302OR operation, 17Output, 270Overloading, 71–72, 80override keyword, 72
PPaint Event, selecting for PictureBox window,
67PaintEventArgs object, 67PaintEventHandler, 194
Index 383
2
4
2222222222
444
29022 06 pp. 367-394 r5ss.ps 8/21/02 4:55 PM Page 383
Paint event handler, 69, 78Paint events, 66, 118, 193, 310
and Decorator interface, 192handling in C#, 230in watching colors change program, 315
Paint handler, 266Paint method, 194, 342Paint routine, bar plot drawn in, 341Panels, 131, 134, 136, 192Parentheses ()
around conditions, 19data type names enclosed in, 13and switch statement, 22
Parsed stacks, reducing, 276–277ParseObject class, 272ParseObjects, 281Parser class, 274–275, 277, 280ParseVar class, 275ParseVar object, 273ParseVerb class, 275ParseVerb object, 273Parsing, 49
interaction of classes performing, 278objects used in, 272–276
Parsing hierarchy, for Interpreter pattern, 273Pascal, 19Pattern groupings, 311Pattern Hatching (Vlissides), 361“Pattern mining,” 6Peek method, 95Pen object, 67, 77Pens, and Paint method, 194PerennialGarden class, 117Person, instances of in Company, 84Person class, 81
derived from Address class, 129and inheritance, 82–83with private, protected, and public
variables, and methods, 82UML diagram for with/without method
types, 82
pic_Paint event handler, 347picPaint handler, 230PictureBox
control, 316inserting on a Form, 66
Picturebox level, mouse motion checked at,229
PictureBox window, Paint Event selected for,67
Pie charts, 338Placeholder classes, and template classes, 352Plant object, 116Plot click method, 136PlotPanel class, 347Plots, drawing in C#, 341PlotStrategy class, 344
instances of, 338PlotWindow class, 345Pluggable adapters, 166Plus sign (+), to combine strings, 17Pointers, 26, 62Polymorphic methods, 72pop method, 271Positioner class, 227Prefix characters, and numeric constants, 14Prefixes, 58PrelimEvent class, 108, 109, 110, 112Price class, 208, 213, 218PriceKey, Price table with, 207Price query, building, 207–208Price table, 207, 218
building, 215–218in Grocery Database, 216
PRINT, 273Print object, 273PrintSpooler class, writing skeleton of, 125Private methods, 48, 53, 63, 71Privileged access
and Iterator pattern, 290and Memento pattern, 301
Process button, 60
384 Index
67
67
67
67
29022 06 pp. 367-394 r5ss.ps 8/21/02 4:55 PM Page 384
Product class, 170ProductList class, 173Product objects, 173, 174, 175ProductTable class, 173ProductTable version, of VisList, 172Programming, object-oriented, 1Programming style, in C#, 58Programs
on CD-ROM, 41, 63, 80, 106, 113, 121,127, 139, 154, 167, 177, 190, 198, 221,232, 237, 253, 268, 282, 299, 312, 319,336, 344, 352, 363
interpreters introduced into, 281Mediator and changes in behavior of, 298Seeding, 111–112simple C#, 16–17simplest Window, in C#, 32–34simple temperature conversion, 43–45triangle drawing, 350–351undoable, 264watching colors change, 314–317Windows Controls, 40–41
Properties, classes and, 56–58Properties window, 66
MouseMove event selected from, 231Property methods, 56, 58, 63protected keyword, 71Protected methods, 71Protected variables, 71Prototype, re-sort of left list box shown with,
146Prototype managers, 152–153Prototype pattern, 98, 141–154, 154
and cloning in C#, 142and cloning the class, 146–147consequences of, 153and prototype managers, 152–153using, 142–145, 147–152
Prototype program simple, 145sorted results of, 145
Prototype Registry, 153Proxy image display, with image load
shown, 236Proxy pattern, 155, 233–238
comparison with related patterns, 237copy-on-write, 232, 237program on the CD-ROM, 237proxies in C#, 236sample code, 234–236use of, 233–234
Public methods, 48, 53, 63, 71push method, 271
QQueries, executing in ADO.Net, 205Queue object, 90Queuing of commands, 257QuickImage class, 235Quit key, 248Quotes ('), characters enclosed in, 14
RRadio button events, handling, 119Radio buttons (or option buttons),
37, 281Reading
opening file for, 96text files, 93
readLine method, 96Recognition, and learning design
patterns, 6Rectangle
drawing in PictureBox on form, 66square created from, 69–71
Rectangle button, 302, 307, 321Rectangle class, 68, 77, 229, 306
DoubleRect class derived from, 72, 73instance of, 69Square class derived from, 69–70, 71
Rectangle drawing program, 69Rectangle state object, 324
Index 385
2
4
2222222222
444
29022 06 pp. 367-394 r5ss.ps 8/21/02 4:55 PM Page 385
RectButtoncommand class, 310Command objects for, 309
Rect button, behavior of, 323rects property, 333RectState object, 324Red button, 260RedButton class, 257RedCommand Class, 265, 267RedCommand object, 260, 265Red menu item, 260Red radio button, in watching colors change
program, 314References, to arrays, 88Refined abstraction, in Bridge pattern, 169Refresh method, 119, 192registerInterest method, 314Registry
of Prototype classes, 153and Singleton instantiation, 126
Relational database, 270remove method, 183, 188, 308repaint method, 347Report Generators, 270–271Responsibilities, Decorator pattern and, 198restore method, 308, 332Right shift n places (>>n), 18Rows, 199
adding to database tables using ADO.Net,206–207
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
specifying order of, 281setBounds method, 341setFill method, 333setPenColor method, 344setPlotBounds(), 341Set property, and Rectangle class, 306setSelected method, 333setText method, 295SexSwimData class, 148, 149, 151Shallow copy, 147Shape class, 77, 79Shape objects, 78Sharable objects, 231–232Signatures, 71, 76Simonyi, Charles, 58SimpleComposite example, 188–189
386 Index
67
67
67
67
29022 06 pp. 367-394 r5ss.ps 8/21/02 4:55 PM Page 386
Simple Factory pattern, 97, 99building, 101–103sample code, 100two derived classes, 100–101workings of, 99–100
SimpleHello form, after clicking Say Hellobutton, 33
Single interface Mediators, 299Single quote (\'), 15 SingletonException:Exception class, 124Singleton pattern, 8, 9, 98, 123–127, 154
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
of 500 free, 112of swimmers, 107
StraightSeeding class, 110, 111StraightSeeding subclass, 108, 109Strategy pattern, 239, 337–344, 345
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
StreamReader object, 93StreamWriter object, 93String class, Split method of, 51string object, 31Strings, 13–14, 27StringTokenizer class, 51–52, 55, 56, 71–72,
142, 271, 274struct types, 26Structural patterns, 6, 97, 155–237
Adapter, 157–167Bridge, 169–177Composite, 179–190Decorator, 191–198Façade, 199–221Flyweight, 223–232Proxy, 233–237summary of, 237
Structural programs, summary of, 237–238Structured Query Language, 202, 270Subclasses, 107, 129, 232
and Abstract Factory pattern, 120of DrawObject, 353of InterpChain, 280and interpret operation, 279and Prototype pattern, 148, 152, 153and Singleton, 126and Template pattern, 345and visitor classes, 360
Subject, and Observer pattern, 314Subject interface, 314Subjects, observers and abstract coupling to,
318Subordinates, ArrayList, 188subordinates method, 182Subsystems, and Façade pattern, 199, 220Subtraction operator (-), 18 Suffix characters, and numeric constants, 14Superclasses, 107SwimData class, 143, 146, 148
UML diagram for, 152SwimInfo class, 151Swimmer class, 53, 54, 55, 56–58, 109, 142Swimmer object, 157, 159Swimmers, straight seeding of, 107SwimmerTimes display program, revised
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
for Scratch, Disqualification, and NoTime, 50
TimerCallback class, 234timerCall method, 234Timer class, 234Times class, 55
simple parsing program using, 49TimeSwimData class, 151Tokenizer class, 51–52Tokenizer demo, 53Tokens
parsing language symbols into, 271strings separated into, 51
ToolbarButtons, in C#, 309Toolbars, 40, 189Toolbox
new control shown on, 74TextBox selected from, 33
ToolTips, 39, 40top method, 271ToString method, 132, 135TPaint method, 351Tree adapter, 166TreeAdapter class, 163, 175TreeDemo program, 164TreeList class, 40, 175Tree list component, and Bridge, 176Tree list display, of composite with display of
parent nodes, 188TreeView, 163–164, 189TreeView control, corporate organization
shown in, 186TreeView list, 185TreeView pattern, 9Triangle class, 347, 350
draw code in, 351three subclasses of, 348
Index 389
2
4
2222222222
444
29022 06 pp. 367-394 r5ss.ps 8/21/02 4:55 PM Page 389
Triangle drawing program, 350–351TriangleForm class, 350Triangles
drawing, 349–350, 351drawing isosceles, 349–350, 351drawing standard, 349, 351
TrigButterfly class, 105true reserved word, 14, 17try block, 125, 205
and exceptions, 90file manipulation code enclosed in, 94
Two-way adapters, 166Type checking, and registry approach, 126
UUML. See Unified Modeling LanguageUML diagrams, 1, 81–86
and annotation, 85–86for Bridge pattern, 173of Chain of Responsibility program class
structure, 247of CommandHolder approach, 262and composition, 84–85for Decorators, 197for drawing program using Memento, 311and inheritance, 82–83of inheritance relationships in Builder
pattern, 138and interfaces, 84of observer interface and subject interface
implementation of Observer pattern,317
showing Employee derived from Person,83
of Strategy pattern, 343for various SwimData classes, 152WithClass, 86
UndoButton, 302Command objects for, 309and rectangles drawing program with
Memento, 302, 304
Undo command demoprogram drawing red and blue lines,
263program drawing red and blue lines after
Undo button clicked, 264UndoCommand object, 265Undo commands, 301Undo function, with Command patterns,
262–267unDo list
and Caretaker class, 307, 308handling, 331–333
unDo method, 265Undo program, classes implementing in
Command pattern implementation, 267
Undo requests, 257Unicode, 12Unified Modeling Language, 81Unreasonable values, handling, 51Unsafe blocks, 26Unsafe mode, 27Unsafe sections of C# code, pointers used
within, 62Unselected instance, of Folder, 228, 229User commands, command interpreter for
parsing, 270User interfaces, command objects in,
309–310using statement, 16
VVacation data
for bosses, 359for employees, 356–359
Vacations button, 359VacationVisitor class, 356Value conversion, classes used for,
48–51value keyword, 56Value method, 289
390 Index
67
67
67
67
29022 06 pp. 367-394 r5ss.ps 8/21/02 4:55 PM Page 390
Variables, 11, 15–16declaring as public, private, and protected,
71declaring as they are used, 15–16delegate, 59protected, 71static, 123
VAR type, 273VarVarParse class, 280VBA. See Visual Basic for ApplicationsVB.NET
and C#, 29as managed language, 30
VB7, 30VeggieGarden class, 116VERB type, 273Video data capture, and compression
schemes, 338View, 4virtual keyword, 72Virtual methods, 347VisCircle class, 333, 335Visiting, meaning of, 354visit method, 354, 358, 360Visitor class, 354, 358, 360
triangle classes visited by, 354Visitor object, 355Visitor pattern, 239, 353–363
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
Visitors, catch-all operations with, 360–361VisList interface, 173, 175, 176VisList variable, 171VisRectangle class, 304, 305–306, 333–335
Drawing interface implemented by, 333VisCircle inheriting from, 333, 335
VisRectangle instance, 306Visual Basic, 19
C# roots in, 29major differences between C# and, 11
Visual Basic Design Patterns: VB6 andVB.NET, 4
Visual Basic for Applications, 269Visual Basic.NET, 11Visual command interpreter program sample,
Chain of Responsibility pattern, 243Visual controls, interactions between,
292–293Visual Studio IDE, and mouse move event
handler, 230Visual Studio.NET, 20, 31, 32, 86, 203
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