+ All Categories
Home > Documents > Index [ptgmedia.pearsoncmg.com] · 2009. 6. 9. · INDEX 331 Constructors abstract class design,...

Index [ptgmedia.pearsoncmg.com] · 2009. 6. 9. · INDEX 331 Constructors abstract class design,...

Date post: 17-Aug-2020
Category:
Upload: others
View: 0 times
Download: 0 times
Share this document with a friend
20
327 A Abbreviations FxCop rules for, 287 in identifier names, 43–44 Abrams, Brad abstract class design, 84, 85 acronym capitalization conventions, 37–38 acronyms in identifiers, 44 addition through subtraction principle, 22 API specification, 312 arrays, 209 assemblies, namespaces, 49 Basic Dispose Pattern implementation, 253 capitalization of compound words/ common terms, 40 choice between enum, Boolean parameters, 152 choice between properties, methods, 117, 120 enum design, 91, 95, 96 enumeration names, 60 Enum.IsDefined, 153–154 event design, 134 exception error message design, 190 exception handling, 192 exception throwing, 187 exceptions, 181 extensibility, 176 factories, 262 framework design, 9 member overloading, 107, 109 namespace names, 50–51 naming conventions, 34, 35 pointer parameters, 162 protected members, 166 type functionality, 68 type names, 55 types and namespaces, 71, 72 usability studies, 18 Abstract class contract separation with, 81–82 design guidelines, 83–85 extensibility and, 67 FxCop rules for, 293 Abstractions base classes for implementation of, 173 choice between class, interface, 77–83 extensibility with, 170–172 layered architecture and, 29–30 limiting for self-documenting object models, 28–29 Optional Feature Pattern and, 264– 267 AccessViolationException, 199–200 Acronyms capitalization conventions for, 35, 36–38 capitalization rules for, 284–285 Index Abrams_IDX.fm Page 327 Friday, August 19, 2005 7:15 PM
Transcript
Page 1: Index [ptgmedia.pearsoncmg.com] · 2009. 6. 9. · INDEX 331 Constructors abstract class design, 83–84 for aggregate components, 239, 241–242 on exceptions, 202 factories vs.,

327

AAbbreviationsFxCop rules for, 287

in identifier names, 43–44Abrams, Brad

abstract class design, 84, 85acronym capitalization conventions,

37–38acronyms in identifiers, 44addition through subtraction

principle, 22API specification, 312arrays, 209assemblies, namespaces, 49Basic Dispose Pattern

implementation, 253capitalization of compound words/

common terms, 40choice between enum, Boolean

parameters, 152choice between properties, methods,

117, 120enum design, 91, 95, 96enumeration names, 60Enum.IsDefined, 153–154event design, 134exception error message design, 190exception handling, 192exception throwing, 187exceptions, 181extensibility, 176

factories, 262framework design, 9member overloading, 107, 109namespace names, 50–51naming conventions, 34, 35pointer parameters, 162protected members, 166type functionality, 68type names, 55types and namespaces, 71, 72usability studies, 18

Abstract classcontract separation with, 81–82design guidelines, 83–85extensibility and, 67FxCop rules for, 293

Abstractionsbase classes for implementation of,

173choice between class, interface, 77–83extensibility with, 170–172layered architecture and, 29–30limiting for self-documenting object

models, 28–29Optional Feature Pattern and, 264–

267AccessViolationException, 199–200Acronyms

capitalization conventions for, 35, 36–38

capitalization rules for, 284–285

Index

Abrams_IDX.fm Page 327 Friday, August 19, 2005 7:15 PM

Page 2: Index [ptgmedia.pearsoncmg.com] · 2009. 6. 9. · INDEX 331 Constructors abstract class design, 83–84 for aggregate components, 239, 241–242 on exceptions, 202 factories vs.,

INDEX328

Acronyms (continued)FxCop rules for, 287in identifier names, 43–44

Active Server Pages (ASP), 10Addition through subtraction, 22Aggregate components, 235–243

component-oriented design, 237–239description of, 235–237design guidelines, 240–243factored types and, 240

Alcazar, Mark, 229Alias names, 44–46Allocation, 74–75Anderson, Chris

choice between class, interface, 82custom event handler design, 138developer methodologies, 17field design, 140low barrier to entry principle, 20, 21

APIs. See Application programming interfaces

Application development, 1–3Application model namespace, 52Application programming interfaces

(APIs)application development, 1, 2design specification, 14–15exceptions for consistency, 179layered architecture principle, 29–31low barrier to entry principle, 19–23naming new versions of existing,

46–48sample API specification, 311–317scenario-driven design principle,

13–19self-documenting object models

principle, 23–29well-designed framework, 3

Applied Microsoft.NET Framework Programming (Richter), 43, 44–45

Architecture, layered architecture principle, 29–31

ARGB value, 38Argument checking, 161Argument exceptions, 304

ArgumentException, 198–199ArgumentNullException, 198–199ArgumentOutOfRangeException,

198–199Arguments

parameter passing, 155–157validating, 152–155

ArrayList, 212Arrays

choice between collections and, 218–219

choice between properties, methods, 119–120

design usage guidelines, 207–209FxCop rules for, 305groupings of types, 67–68members with variable number of

parameters, 157–161ASP (Active Server Pages), 10ASP.NET, 30, 31Assembly

FxCop rules for, 288naming conventions for, 48–49

Async callback, 244Async Pattern, 243–248

asynchronous operations, 243–244design guidelines, 244–246elements of, 244implementation example, 247–248

Async Result object, 244Asynchronous operations

Async Pattern, 244–248function of, 243–244

AttributesFxCop rules for, 305–306groupings of types, 67–68System.Attribute, 209–211

AttributeUsageAttribute, 210Avalon, 20, 21

BBase class

choice between class, interface, 81in derived class name, 55–56extensibility and, 67, 172–174

Abrams_IDX.fm Page 328 Friday, August 19, 2005 7:15 PM

Page 3: Index [ptgmedia.pearsoncmg.com] · 2009. 6. 9. · INDEX 331 Constructors abstract class design, 83–84 for aggregate components, 239, 241–242 on exceptions, 202 factories vs.,

INDEX 329

virtual members documentation and, 169

Base suffix, 174Base types, 301Basic Dispose Pattern

finalizable types and, 256–260guidelines for, 250–251implementation guidelines, 251–256

Begin methodAsync Pattern design, 245–246Async Pattern implementation, 248function of, 244

BinaryReader, 18Bitwise operations, 97Boolean parameters

enum parameters and, 150–152member overloading, 107

Boolean propertiesnaming of, 62for Optional Feature Pattern, 267

Box, 75Boxing

explicit interface member implementation and, 111–112

from Object.Equals method, 222Brace usage conventions, 274–275Brumme, Christopher

Async Pattern implementation, 248exception from constructor, 127exception handling, 193, 194fail fast, 185–186hash code, 226standard exception types, 199–201type constructor design, 131, 132unhandled exception handler, 182–

183virtual calls, 130

By-value parameter, 155

CC++

enumeration names in, 60finalizer in, 252static class in, 85subclassing, 10

varargs methods, 160–161virtual calls in, 130

C#constructor design and, 128finally blocks of, 194indexed property design and,

123–124indexer name in, 123operator overloads and, 143static class in, 85types, namespaces and, 72

C# coding style conventions, 273–279comments, 277–278file organization, 278–279general style, 274–276goals of, 273naming, 277

Callbacksevent design guidelines, 132–138extensibility with, 166–168virtual members vs., 168

CamelCasing conventionacronym capitalization conventions,

37identifier naming conventions, 34,

35–36for parameter names, 64

Capitalization conventions, 34–41acronyms, 36–38case sensitivity, 41compound words, common terms,

39–40FxCop rules for, 284–286identifiers, 34–36

Case insensitivityattribute and, 211support of, 41

Case sensitivity. See also Capitalization conventions

FxCop rules for, 286guidelines for, 41

Catch blockfor cleanup code, 193–194exception handling, 191

Catch clauses, 193–194

Abrams_IDX.fm Page 329 Friday, August 19, 2005 7:15 PM

Page 4: Index [ptgmedia.pearsoncmg.com] · 2009. 6. 9. · INDEX 331 Constructors abstract class design, 83–84 for aggregate components, 239, 241–242 on exceptions, 202 factories vs.,

INDEX330

Certainty value, 283Change events, 124–125Clark, Jason, 185Clarke, Steven

Boolean parameters, 151enum design, 91–92exception wrapping, 196explicit interface member

implementation, 112method names, 61return codes, 180

Classesabstract class design, 83–85base classes, extensibility with,

172–174choice between interfaces and, 77–83choice between struct and, 74–76function of, 67FxCop rules for choice between

interface and, 293–294FxCop rules for names of, 288–290groupings of types, 68naming conventions for, 54–60sealing, 175–176static class design, 85–86unsealed classes, 164–165

Cleanup code, 193–194Cloning, 221Closed-form compound word, 39CloseHandle, 181CLR. See Common Language RuntimeCLS (Common Language

Specification), 43Coding styles, 14. See also FxCopCollections

arrays and, 207, 208choice between arrays and, 218–219custom, 219–220design usage guidelines, 211–213FxCop rules for, 306–307groupings of types, 67–68as parameters, 213–214properties, return values, 214–217snapshot vs. live, 217–218

Collection<T>

base suffix and, 174for properties, return values, 214implementation of base class, 173return subclass of, 216

ComException, 201Comments, 277–278Common Language Runtime (CLR)

assemblies, DLLs and, 48–49capitalization conventions, 34case sensitivity, 41default arguments and, 110exception wrapping, 195interface design and, 86language-specific names, 44–46memory management, 248–249standard exception types and,

199–201type constructor design and, 131types in, 67

Common Language Specification (CLS), 43

Common terms, 39–40Company name, 50Comparison operators, 223Component-oriented design

aggregate components and, 238–239aggregate components for, 235–243Create-Set-Call usage pattern,

237–238Compound words

capitalization conventions for, 39–40capitalization rules for, 285

Concrete typeabstract class design, 84–85extensibility with abstractions, 171

Consistencyexceptions and, 179of naming conventions, 33of self-documenting object models,

27–28of well-designed framework, 6

Constant fields, 140Constructor parameters

for attribute properties, 210–211Booleans for, 152

Abrams_IDX.fm Page 330 Friday, August 19, 2005 7:15 PM

Page 5: Index [ptgmedia.pearsoncmg.com] · 2009. 6. 9. · INDEX 331 Constructors abstract class design, 83–84 for aggregate components, 239, 241–242 on exceptions, 202 factories vs.,

INDEX 331

Constructorsabstract class design, 83–84for aggregate components, 239,

241–242on exceptions, 202factories vs., 261–262struct design, 89–90

Constructors, design guidelinesconversion operators, 146–147event design, 132–138event handler design, custom, 138field design, 139–141FxCop rules for, 297–298general guidelines, 125–130operator overloads, 141–146overloading operator ==, 146parameter design, 148–150parameter passing, 155–157parameters, choice between enum/

Boolean, 150–152parameters, members with variable

number of, 157–161pointer parameters, 161–162type constructor design, 131–132validating arguments, 152–155

Contract, 80, 81–82Convenience overloads, 21, 23Conversion operators, 146–147Core namespaces, 53Create-Set-Call usage pattern

aggregate component design, 241of component-oriented design,

237–238Custom attributes, 209–211Custom collections, 219–220Custom exceptions

design guidelines, 202–203exception throwing, 189FxCop rules for, 305

Customization, protected members for, 165–166

Cwalina, Krzysztofabstractions, 29, 172acronym capitalization conventions,

37

aggregate components, 236, 237, 240, 241

API specification, 313–314, 315attributes, 211base classes, 173choice between class, interface, 80, 81custom collections, 219delegate calls, 167exception filters, 188exception throwing, 184–185explicit interface member

implementation, 112extensibility limitations, 175factories, 263factorization, 265framework design, 8, 261ICloneable interface, 221low barrier to entry principle, 22naming conventions, 33nested types, 103operator overloads design, 142property names, 62scenario-driven design principle, 14sealing, 176self-documenting object models

principle, 24, 25standard exception types, 198subnamespaces, 73type names, 54, 55types and namespaces, 70usability studies, 17virtual members, 169word choice conventions, 42

DDeallocation, 74–75Debugging

exceptions, 194–195with Object.ToString, 227–228

Deep-copy, cloning, 221Default arguments, 109–110Default constructors. See also Instance

constructorsdesign guidelines, 126–130for struct, 89

Abrams_IDX.fm Page 331 Friday, August 19, 2005 7:15 PM

Page 6: Index [ptgmedia.pearsoncmg.com] · 2009. 6. 9. · INDEX 331 Constructors abstract class design, 83–84 for aggregate components, 239, 241–242 on exceptions, 202 factories vs.,

INDEX332

Default values, 121Delegates

events and, 132extensibility with callbacks, events,

166–168groupings of types, 67–68

Derived class, 55–56Descriptive identifier names, 25–26Descriptive parameter names, 64–65Design conventions, framework, 2–3Design patterns

aggregate components, 235–243Async Pattern, 243–248Dispose Pattern, 248–260factories, 260–263FxCop rules for, 309Optional Feature Pattern, 264–267Template Method Pattern, 267–269timeouts, 269–271

Design Patterns (Gamma et al), 267.Design subnamespace, 73Design usage guidelines. See also

FxCoparrays, 207–209attributes, 209–211collections, 211–220equality operators, 231–233ICloneable interface, 221IComparable<T>, IEquatable<T>,

222–223IDisposable, 223System.Object, 224–228System.Uri, 228–230System.Xml Usage, 230–231

Dictionary suffix, 220Dictionary<TKey,TValue>, 212–213Disposable types, 250Dispose (bool) method

Basic Dispose Pattern implementation, 251–256

finalizable types and, 257Dispose methods, 250Dispose Pattern, 248–260

Basic Dispose Pattern implementation, 251–256

finalizable types, 256–260IDisposable known as, 223implementation guidelines, 249–251memory management, 248–249

DLL. See Dynamic Link LibraryDocumentation

of abstractions, 171self-documenting object models

principle, 23–29Doer

danger of, 204preconditions check with, 186

Dot separators, 65Duffy, Joe, 253Dussud, Patrick, 122Dynamic Link Library (DLL)

FxCop rules for, 288naming conventions for, 48–49

E80/20 rule, 8Elapsed time, 15Encapsulation, 139Enclosing type, 101–102End method

Async Pattern design, 245, 246Async Pattern implementation, 248function of, 244

Enum parameterschoice between Boolean parameters

and, 150–152validation of, 153–154

Enumerators, 102Enum.IsDefined, 153–154Enums

design guidelines, 91–101function of, 67FxCop design rules for, 294–295FxCop rules for names of, 290groupings of types, 68naming conventions, 59–60

Equality operatorsIEquatable<T> and, 223use guidelines, 231–233

Error codes

Abrams_IDX.fm Page 332 Friday, August 19, 2005 7:15 PM

Page 7: Index [ptgmedia.pearsoncmg.com] · 2009. 6. 9. · INDEX 331 Constructors abstract class design, 83–84 for aggregate components, 239, 241–242 on exceptions, 202 factories vs.,

INDEX 333

exception throwing and, 184–185exceptions, performance and, 203for timeout expiration, 271

Error handling code, 180Error message

exception error message design, 189–191

exception error message terminology, 196

Error reportingcomponent-oriented design and, 238exceptions for, 179–183

Event argumentsdescription of, 132design guidelines, 135naming of, 63–64

Event handlerscustom design, 138design guidelines, 134–135naming of, 63

Event handling method, 132EventArgs, 135EventLog component, 236Events

aggregate components and, 239, 242design guidelines, 132–138extensibility with, 166–168FxCop design rules, 298FxCop name rules, 291–292naming conventions, 63–64

Ex abbreviationavoidance of, 47use of, 40

Exception builder methods, 187–188Exception filter blocks, 188Exception handler, 182–183Exception handling, 303Exception throwing

Async Pattern design and, 245–246choice of exception type, 189dispose (bool) method and, 255–256error message design, 189–191exception handling, 191–195FxCop rules for, 303, 304guidelines for, 183–188

standard exception types and, 199for timeouts, 270–271wrapping exceptions, 195–197

Exception types, standardArgumentException,

ArgumentNullException, and ArgumentOutOfRangeException, 198–199

ComException, SEHException, 201for exception throwing, 189ExecutionEngineException, 201FxCop rules for, 303–304InvalidOperationException, 198NullReferenceException,

IndexOutOfRangeException, and AccessViolationException, 199–200

OutOfMemoryException, 200–201StackOverflowException, 200System.ApplicationException,

197–198System.Exception and

System.SystemException, 197Exceptions

aggregate components and, 238, 239argument validation and, 153benefits of, 179–183from constructor, 127conversion operators and, 147custom, 202–203error message design, 189–191exception handling, 191–195exception message resource names,

65FxCop rules for, 303–305groupings of types, 67–68for low barrier to entry, 23performance and, 203–205in property getter, 121–122for self-documenting object models,

26–27standard exception types, 197–201throwing, 183–188, 189type constructor design and, 131wrapping exceptions, 195–197

Abrams_IDX.fm Page 333 Friday, August 19, 2005 7:15 PM

Page 8: Index [ptgmedia.pearsoncmg.com] · 2009. 6. 9. · INDEX 331 Constructors abstract class design, 83–84 for aggregate components, 239, 241–242 on exceptions, 202 factories vs.,

INDEX334

Execution failuredefinition of, 183report by exception throwing, 185

ExecutionEngineException, 201Expense, framework, 3–4Experimentation, 19–23Explicit conversion operators, 146–147Explicit interface member

implementation, 111–115Extensibility

abstractions, 170–172base/abstract classes and, 67base classes, 172–174choice of mechanisms, 163–164events, callbacks, 166–168extensibility mechanisms, 163–172protected members, 165–166unsealed classes, 164–165virtual members, 168–170

FxCop rules for, 302–303sealing, 174–177Template Method Pattern for,

268–269Extensible Markup Language (XML)

FxCop rules for System.XML, 308System.XML, 230–231

FFactored design

Optional Feature Pattern and, 266for optional features, 264–265

Factored typesof aggregate components, 240design guidelines, 243

Factoriesdescription of, 260–261guidelines for, 261–263

Factory methoddescription of, 260–261guidelines for, 263instead of constructor, 126

Factory typesdescription of, 260function of, 261

naming, 263Fail fast, 185–186Failures

exception benefits and, 180–183exception throwing, 183–188execution failure, 183reporting, 179

Fanning, Mikeargument exceptions rule, 304exception filters, 303freeware version of FxCop, 284FxCop analysis capabilities, 281FxCop capitalization rules, 286FxCop constructor design rules, 298FxCop, custom rules with, 282FxCop evolution, 283ID issue, 285root cause analysis of FxCop, 292spelling checks, 287Visual Studio and FxCop rules, 290

Features, Optional Feature Pattern, 264–267

Fieldsdesign guidelines, 139–141FxCop design rules, 298–300FxCop name rules, 292naming conventions, 64

File organization, 278–279Filters, 188Finalizable types

definition of, 249implementation guidelines, 256–260

Finalize methodconstructor design, 127Dispose Pattern and, 250release of unmanaged resources, 249

FinalizersDispose Pattern implementation,

251–256finalizable types, 256–260release of unmanaged resources, 249

Finally blocksfor cleanup code, 194exception throwing and, 188

Flag enums

Abrams_IDX.fm Page 334 Friday, August 19, 2005 7:15 PM

Page 9: Index [ptgmedia.pearsoncmg.com] · 2009. 6. 9. · INDEX 331 Constructors abstract class design, 83–84 for aggregate components, 239, 241–242 on exceptions, 202 factories vs.,

INDEX 335

design guidelines, 96–100design of, 91–92FxCop design rules, 295

Framework. See also .NET FrameworkAPI specification sample, 311–317application development history, 1–3well-designed framework, 3–6

Framework design fundamentals. See also FxCop

layered architecture principle, 29–31low barrier to entry principle, 19–23progressive frameworks, 9–12for range of developers, 8–9scenario-driven design principle,

13–19self-documenting object models

principle, 23–29simplicity/power, 7–8usability of, 12–13

FxCopdefinition of, 281–282design patterns rules, 309evolution of, 282–283exceptions rules, 303–305extensibility design rules, 302–303member design rules, 296–302naming guidelines rules, 284–293process of, 283type design guidelines rules, 293–295usage guidelines rules, 305–309

GGarbage Collector (GC), 248–249GC.SurpressFinalize method

Basic Dispose Pattern implementation, 253–254

function of, 249–250Generator, 215Generic type parameters, 56–57George, Kit, 48Get-only properties

property design, 120for required arguments, 210

Good practices, 5Gray, Jan, 169

Grep test, 44Grunkemeyer, Brian

Async Pattern design, 246Async Pattern implementation, 248static class, 86

Gunnerson, Eric, 136–137

HHandle property, 118Harrison, Sheridan, 281–309Hash, 225–226Hashtable, 212–213Hejlsberg, Anders

explicit interface member implementation, 111

multiframework design, 10–11parameter passing, 156value of enum, 99

Hierarchyinterface for polymorphic hierarchy,

82types, namespaces and, 70–74

High-level APIs, 29–31Hungarian naming convention, 42

II, 55, 56IAsyncResult.CompletedSynchronously,

246ICloneable interface

design usage guidelines, 220, 221documentation for, 171

ICollection, 213–214ICollection<T>

explicit interface member implementation, 113

for properties, return values, 214–215use guidelines, 213–214

IComparable<T>, 222–223Identifier names

abbreviations, acronyms in, 43–44acronym capitalization conventions,

36–38capitalization rules for, 34–36, 284conventions for, 276FxCop word choice rules, 286–287

Abrams_IDX.fm Page 335 Friday, August 19, 2005 7:15 PM

Page 10: Index [ptgmedia.pearsoncmg.com] · 2009. 6. 9. · INDEX 331 Constructors abstract class design, 83–84 for aggregate components, 239, 241–242 on exceptions, 202 factories vs.,

INDEX336

Identifier names (continued)language-specific names, avoidance

of, 44–46for self-documenting object models,

25–26word choice conventions, 42–43

IDisposable, 223IEnumerable, 211, 213–214IEnumerable<T>

collection parameters, 213–214collections implementation of, 211on custom collection, 219as generator, 215for properties, return values, 214–215

IEnumerator, 213IEnumerator<T>, 213IEquatable<T>

design usage guidelines, 222–223Object.Equals and, 225struct design, 90

IList<T>, 214–215Implementation

Async Pattern, 247–248Basic Dispose Pattern, 251–256

Implicit conversion operators, 146–147Indent usage conventions, 276Indexed property, 122–124IndexOutOfRangeException, 199–200Infrastructure namespace, 52–53Inheritance

base classes and, 173unsealed classes and, 164–165

Inheritance hierarchyinterface design and, 86–87type names and, 54–55

Initializationfor aggregate components, 241low barrier to entry principle and,

20–21, 22–23Insert method, 180Instance constructors. See also Default

constructorsconstructor design guidelines,

126–130type constructors and, 125–126

Instrumentation, 183Int32, 95, 96Integer timeouts, 270Integration, of framework, 5–6Intellisense

API names and, 47Boolean property names and, 62factories and, 261identifier names and, 26types, namespaces and, 71

Interface members, 296Interfaces

choice between classes and, 77–83, 293–294

design guidelines, 86–89explicit interface member

implementation, 111–115function of, 67FxCop design rules, 294FxCop name rules, 288–290groupings of types, 68ICloneable interface, 221naming conventions for, 54–60nested types and, 103

Internal constructors, 84.Interop subnamespace, 73–74Invalid states, 238–239InvalidOperationException

Async Pattern design and, 246component-oriented design and, 238use guidelines, 198

It-Just-Works concept, 236Item, 123IXPathNavigable, 230–231

JJagged arrays, 208–209

KKay, Alan, 7–8Keyed collections, 216–217Keywords, 43

LLanguage-specific names

avoidance of, 44–46

Abrams_IDX.fm Page 336 Friday, August 19, 2005 7:15 PM

Page 11: Index [ptgmedia.pearsoncmg.com] · 2009. 6. 9. · INDEX 331 Constructors abstract class design, 83–84 for aggregate components, 239, 241–242 on exceptions, 202 factories vs.,

INDEX 337

FxCop rules for, 287–288Languages

exception message and, 190–191scenario code samples and, 14, 16

Layered architecture principle, 29–31Learning curve

of multiframework platform, 9–10of progressive framework, 11–12

List<T>, 212Live collections, 217–218Lossy conversions, 147Low barrier to entry principle

description of, 19–21guidelines for, 21–23

Low-level APIs, 29–31

MManaged memory, 248Mariani, Rico

argument validation, 152, 155choice between properties, methods,

116, 117, 120enum design, 94, 95event design, 136exception wrapping, 196explicit interface member

implementation, 112, 114, 115extensibility, 169indexed property design, 122interfaces, 83marker interface, 88member overloading, 106, 110Object.ToString, 228operator overloads, 144parameter design, 148, 149parameter passing, 156params array parameter, 158, 160pit of success, 12pointer parameters, 161property change notification events,

124–125property design, 121reference/value types, 75–76Tester-Doer pattern, 204ToString, 202TryParse pattern, 205

type design, 69types and namespaces, 71, 72varargs methods, 161

Marker interfaces, 87–88MarshalByRefObject, 81Member design

constructors, general guidelines, 125–130

constructors, type constructor guidelines, 131–132

conversion operators, 146–147event design, 132–138event handler design, custom, 138explicit interface member

implementation, 111–115field design, 139–141FxCop rules for, 296–302indexed property design, 122–124member overloading, 105–110operator overloads, 141–146overloading operator ==, 146parameter design, 148–150parameter passing, 155–157parameters, choice between enum/

Boolean, 150–152parameters, members with variable

number of, 157–161pointer parameters, 161–162properties/methods, choice between,

115–120property change notification events,

124–125property design, 120–122validating arguments, 152–155

Member overloadingdesign guidelines for, 105–110FxCop rules for, 296

Membersnaming new versions of existing

APIs, 46–48protected members, extensibility

with, 165–166sealing, 175, 176–177virtual members, extensibility with,

168–170

Abrams_IDX.fm Page 337 Friday, August 19, 2005 7:15 PM

Page 12: Index [ptgmedia.pearsoncmg.com] · 2009. 6. 9. · INDEX 331 Constructors abstract class design, 83–84 for aggregate components, 239, 241–242 on exceptions, 202 factories vs.,

INDEX338

Memory managementDispose Pattern, 249–260Garbage Collector, 248–249

Messages, 189–191Method parameters, 269Methods

for aggregate components, 239choice between properties and,

115–120exception throwing and, 185FxCop rules for choice between

properties and, 296–297naming conventions, 60–61operator overloads and, 144–146

MicrosoftFxCop and, 282–283FxCop capitalization rules, 285, 286multiframework design, 9namespace name, 50

Microsoft Office, 182, 190–191Microsoft Windows, 10–11Modes, 242–243Moore, Anthony, 151, 152Morrison, Vance, 100Multiframework platform, 9–11Multiple inheritance, 86–87Mutable types

FxCop rules for field design, 298–299readonly fields and, 141

NName collisions, 71–72Names

for aggregate components, 240, 241for indexed property, 123

Namespaceassemblies, DLLs and, 48FxCop rules for type design

guidelines, 293in layered architecture, 30–31low barrier to entry principle and, 20,

21type design guidelines and, 69–74

Namespace, naming conventions

FxCop rules for namespace names, 288

guidelines for, 49–51type name conflicts, 51–53

Namingc# coding style conventions, 277custom collections, 220factories, 263parameters, 149–150for self-documenting object models,

24–26Naming guidelines

capitalization conventions, 34–41classes, structs, interfaces, 54–60FxCop rules for, 284–293general naming conventions, 41–49namespaces, 49–53parameters, 64–65reasons to use, 33summary, 66type members, 60–64

Nested typesdesign guidelines, 101–103FxCop rules for, 295

.NET Frameworkacronym capitalization conventions,

37–38API specification sample, 311–317base classes of, 173capitalization of compound words/

common terms, 40choice between class, interface, 77–83choice between properties, methods,

117, 120exception types, standard, 197–201low barrier to entry principle and,

22–23memory management, 248–249namespace names, 50–51naming conventions, 25, 33as progressive framework, 11–12self-documenting object models

principle, 28static class in, 86

Abrams_IDX.fm Page 338 Friday, August 19, 2005 7:15 PM

Page 13: Index [ptgmedia.pearsoncmg.com] · 2009. 6. 9. · INDEX 331 Constructors abstract class design, 83–84 for aggregate components, 239, 241–242 on exceptions, 202 factories vs.,

INDEX 339

subnamespaces, 73type design, 69type names, 55, 57–59usability of, 12–13usability studies, 17–18

Nonspecific exceptionscatching/wrapping, 196swallowing, 191–192

NotSupported Exception, 267Null

argument validation, 153collection properties and, 217event design and, 136–137member overloading and, 109as params array parameter, 160

NullReferenceException, 199–200

OObasanjo, Dare, 231Object-oriented programming (OOP)

for application development, 2exceptions and, 179–180extensibility and, 163naming conventions, 42–43

Object.Equalsequality operators and, 232Object.GetHashCode and, 226override, 222, 224–225

Object.GetHashCodeObject.Equals and, 224–225overriding, 225–226

Objectsfactories and, 260–263FxCop rules for, 307self-documenting object models

principle, 23–29Object.ToString, 227–228Office, Microsoft, 182, 190–191OOP. See Object-oriented

programmingOperator!=

IEquatable<T> and, 223use guidelines, 231–233

Operator overloadsdesign guidelines, 141–146

FxCop rules for, 300Operators

conversion operators, design guidelines, 146–147

FxCop rules for, 308–309overloading operator ==, 146

Optional Feature Patternguidelines for, 265–267modeling requirements, 264–265

Optional propertiesof attributes, 210constructor parameters and, 211

Out parametersAsync Pattern design and, 245design guidelines, 149member overloading and, 108passing, 156

OutOfMemoryException, 200–201Overloading operator ==

complexity of, 146design usage guidelines, 231–233IEquatable<T> and, 223

Overloadschoice between properties, methods

and, 116equality operators, 231–233FxCop rules for operator overloads,

300FxCop rules for operators, 308member overloading, 105–110operator overloads, design

guidelines, 141–146Override

Object.Equals, 224–225sealing, 177

OverrideAt method, 265

PParameter passing, 155–157, 301Parameters

Async Pattern design and, 245capitalization conventions for, 35choice between enum, Boolean,

150–152collection, 213–214

Abrams_IDX.fm Page 339 Friday, August 19, 2005 7:15 PM

Page 14: Index [ptgmedia.pearsoncmg.com] · 2009. 6. 9. · INDEX 331 Constructors abstract class design, 83–84 for aggregate components, 239, 241–242 on exceptions, 202 factories vs.,

INDEX340

Parameters (continued)design guidelines, 148–150FxCop design rules, 301–302FxCop name rules, 292indexed property design and, 123member overloading, 105–110members with variable number of,

157–161naming guidelines, 64–65passing, 155–157pointer parameters, 161–162

Parametized constructor, 128Params array parameter

design guidelines, 157–159member overloading and, 108

Parsingfactory for, 262–263TryParse pattern, 204–205

PascalCasing conventionfor acronyms, 284–285for field names, 64identifier naming conventions, 34–36for namespace names, 51for property names, 61for resource names, 65for type names, 55

Passing, parameter, 155–157, 301Patterns. See Design patternsPepin, Brian

Basic Dispose Pattern implementation, 254

choice between properties, methods, 118

contract in abstract class, 82Dispose Pattern, 250event design, 135Intellisense, 71interfaces, 83member overloading, 109parameter passing, 156params array parameter, 158property design, 121virtual members, 168

Performanceexception throwing and, 186

exceptions and, 203–205properties, methods and, 116, 117

Period, 190.Permissions subnamespace, 73Pincus, Jon, 151Pointer parameters, 161–162Post-events, 133–134Power

framework design for, 7–8simplicity and, 3

PowerCollections project, 172Pre-events, 133Preconditions, 186Predefined object instances, 140Prefix

for custom collection name, 220enumeration names and, 60in namespace name, 50type names and, 55, 56

Productivity, 6Programmers, 8Programming languages, 184. See also

Object-oriented programmingProgressive frameworks, 9–12Properties

for aggregate components, 239, 242of attributes, 209–211choice between methods and,

115–120, 296–297collection return from, 214–217design guidelines, 120–122field design and, 139–140FxCop name rules, 291indexed property design, 122–124naming conventions, 61–62property change notification events,

124–125Property bags, 27Property change notification events,

124–125Property getter

arrays for properties and, 219exception from, 121–122snapshot collection and, 217

Property setter, 120–121

Abrams_IDX.fm Page 340 Friday, August 19, 2005 7:15 PM

Page 15: Index [ptgmedia.pearsoncmg.com] · 2009. 6. 9. · INDEX 331 Constructors abstract class design, 83–84 for aggregate components, 239, 241–242 on exceptions, 202 factories vs.,

INDEX 341

Protected accessibility, 170Protected members

explicit interface member implementation, 114–115

extensibility with, 165–166sealing, 176–177unsealed classes and, 164

Protected virtual method, 135–136Public accessibility, 170Public constructors

abstract class design, 83–84default, explicitly declared, 128

Public members, 187Publicly accessible APIs. See also

Design usage guidelinesarrays in, 207–209collections in, 211–220

RRAD (Rapid Application

Development), 10Raise

event design and, 137–138protected virtual method to raise

event, 135–136use of term, 134

Rapid Application Development (RAD), 10

Read-only collectionfor array, 208ReadOnly prefix for, 220

Read-only fieldsarrays and, 207–208design guidelines, 140–141

ReadOnlyCollection<T>for properties, return values, 214–215return subclass of, 216

Rector, Brentcatch blocks, 194exception throwing, 189exceptions and application, 182framework with multiple languages,

16identifier names, 26usability studies, 18

Ref parameter, passing, 155, 156, 157Reference equality, 224Reference parameters, 245Reference test, 172Reference types

choice between class, struct, 74–76equality operators on, 232–233groupings of types, 67–68Object.Equals on, 224, 225

Reflection, 197Renaming, 113–114Required properties, 209–210Reserved enum values, 93Reserved parameters, 148–149Resources

FxCop rules for names of, 292–293naming conventions, 65

Return codeserror handling, 181exception benefits for, 180–181

Return-value-based error reporting, 179–180

Return valuescollection, 214–217of Object.GetHashCode, 226

Richter, Jeffreyabstractions, 171, 172assembly names, 48–49asynchronous operations, 244Basic Dispose Pattern

implementation, 253, 254case sensitivity, 41choice between class, interface, 81, 83choice between properties, methods,

118constructor design, 127default arguments, 110enum design, 92, 97event design, 137exception handling, 192, 193, 194, 195exception message, 190–191exception throwing, 189exception wrapping, 197exceptions for error reporting, 180

Abrams_IDX.fm Page 341 Friday, August 19, 2005 7:15 PM

Page 16: Index [ptgmedia.pearsoncmg.com] · 2009. 6. 9. · INDEX 331 Constructors abstract class design, 83–84 for aggregate components, 239, 241–242 on exceptions, 202 factories vs.,

INDEX342

Richter, Jeffrey (continued)exceptions, program failures,

181–182explicit interface member

implementation, 112field design, 140finalizable types, 259language-specific names, 44–45standard exception types, 197–198,

199static class, 86syntax for exceptions, 184Tester-Doer pattern, 186, 204TryParse pattern, 205type design, 69type names, 55, 56types and namespaces, 70, 71, 72unhandled exception handler, 183value types, 76word choice conventions, 43

Rules. See FxCop

SScenario code samples, 13–16Scenario-driven design principle

description of, 13–14guidelines for, 14–17usability studies, 17–19

Sealingcustom attributes, 211explicit interface member

implementation and, 114extensibility with, 174–177FxCop rules for, 302–303

Securityexception message and, 190explicit interface member

implementation and, 114Security-sensitive information

custom exceptions and, 202–203Object.ToString and, 228

SEHException, 201Self-documenting object models

principleabstractions, limiting, 28–29

consistency, 27–28description of, 23–24exceptions, 26–27naming, 24–26strong typing, 27

Sells, Chrisfinalizable types, 258IEnumerable<T>, 215Object.ToString, 227

Sender parameter, 63Sentinel values, 93–94Set-only properties, 120–121Settable properties

collections and, 214for optional properties, 210

Shallow-copy, cloning, 221Simple enums

example of, 91value of zero on, 95

Simple overloads, 21Simplicity, 3, 7–8Snapshot collections, 217–218Space usage conventions, 275–276Specification sample, API, 311–317StackOverflowException, 200Standard design methodologies, 16–17Standard exception types. See

Exception types, standardStarck, Steve, 266State object, 244Static class

design guidelines, 85–86function of, 67FxCop rules for, 294groupings of types, 68

Static constants, 92Static constructors. See Type

constructorsStatic fields, 131–132Stopwatch class, 312–317StreamReader

choice between class, interface, 78–80usability studies, 18

String-based overloads, 229–230

Abrams_IDX.fm Page 342 Friday, August 19, 2005 7:15 PM

Page 17: Index [ptgmedia.pearsoncmg.com] · 2009. 6. 9. · INDEX 331 Constructors abstract class design, 83–84 for aggregate components, 239, 241–242 on exceptions, 202 factories vs.,

INDEX 343

StringReader, 18Strong typing

enums for, 92FxCop rules for, 306for self-documenting object models,

27Structs

choice between class and, 74–76design guidelines, 89–90explicit default constructors on,

128–129function of, 67FxCop design rules, 294FxCop name rules, 288–290groupings of types, 68naming conventions for, 54–60

Style conventions, 274–276Subnamespace names, 73–74Suffix

for attributes, 210for collections, 220enumeration names and, 59–60naming new versions of existing

APIs, 47type names and, 57–59

Sutter, HerbBasic Dispose Pattern

implementation, 252finalizable types, 259finalizers, 257

Swallow, exceptions, 191–192Syntax, 184System resources

Dispose Pattern for, 249–260memory management, 248–249

System.ApplicationException, 197–198System.ArgumentException, 153System.Attribute, 209–211System.ComponentModel.IComponen

t, 172System.Data, 22–23System.DateTime, 106System.Decimal, 141–142System.Enum, 96–97System.Environment class, 86

System.Environment.FailFast, 185–186System.EventHandler<T>, 134–135SystemEvents, 168System.Exception

throwing, 189use guidelines, 197

System.FlagsAttribute, 97System.IDisposable interface

Basic Dispose Pattern implementation, 251–256

release of unmanaged resources with, 249

System.InvalidOperationException, 198

System.IO namespace, 17–18System.IO.Stream abstract class, 77–80System.IO.Stream class

Basic Dispose Pattern and, 251Optional Feature Pattern and, 266

System.Messaging.MessageQueue, 23System.Net, 21System.Net.WebClient, 236System.Object

Object.Equals, 224–225Object.GetHashCode, 225–226Object.ToString, 227–228release of unmanaged resources, 249

System.Runtime.Serialization namespace, 70

System.ServiceProcess namespace, 237System.SystemException, 197System.TimeoutException, 270–271System.Uri

FxCop rules for, 307–308implementation guidelines, 229–230use guidelines, 228–229

System.Web namespace, 30, 31System.XML

APIs, 61FxCop rules for, 308use guidelines, 230–231

Szyperski, Clemens, 101

TT, 57

Abrams_IDX.fm Page 343 Friday, August 19, 2005 7:15 PM

Page 18: Index [ptgmedia.pearsoncmg.com] · 2009. 6. 9. · INDEX 331 Constructors abstract class design, 83–84 for aggregate components, 239, 241–242 on exceptions, 202 factories vs.,

INDEX344

Technology namespace groups, 53Template Method Pattern, 267–269Tester

danger of, 204preconditions check with, 186

Tester-Doer patternexception throwing and, 203–204preconditions check with, 186

TextReader, 18ThreadPool.QueueUserWorkItem, 248Throwing. See Exception throwingTimeouts

guidelines for, 269–271System.IO.Stream and, 77–80

TimeSpan, 270ToString, 202Trademark, 38Try-catch, 193Try-finally, 193, 194TryParse pattern

guidelines for, 204–205Tester-Doer pattern and, 186

Two-character acronyms, 37Type constructors

design guidelines, 131–132FxCop design rules, 297–298instance constructors and, 125–126

Type design guidelinesabstract class design, 83–85categories of, 67–68class, interface, choice between,

77–83class, structs, choice between, 74–76enum design, 91–101FxCop rules for, 293–295interface design, 86–89namespaces and, 69–74nested types, 101–103static class design, 85–86struct design, 89–90summary, 104

Type members, naming guidelines, 60–64

events, 63–64fields, 64

FxCop rules for, 291–292methods, 60–61properties, 61–62

Type parameters, 56–57Types

constructor design guidelines, 126–130

factored types, 240FxCop name rules, 289–290FxCop type design rules, 293low barrier to entry principle and, 20,

21–22namespace, type name conflicts,

51–53naming, 24–26naming conventions for classes,

structs, interfaces, 54–60naming new versions of existing

APIs, 46–48nested types, 101–103

Types, design usage guidelinesarrays, 207–209attributes, 209–211collections, 211–220equality operators, 231–233ICloneable interface, 221IComparable<T>, IEquatable<T>,

222–223IDisposable, 223System.Object, 224–228System.Uri, 228–230System.Xml Usage, 230–231

UUEF (unhandled exception filter),

182–183Underlying type, 95–96Unhandled exception, 190–191Unhandled exception filter (UEF),

182–183Unhandled exception handler, 182–183Uniform Resource Identifiers (URIs)

FxCop rules for, 307–308System.Uri for, 229–230

Unmanaged resources

Abrams_IDX.fm Page 344 Friday, August 19, 2005 7:15 PM

Page 19: Index [ptgmedia.pearsoncmg.com] · 2009. 6. 9. · INDEX 331 Constructors abstract class design, 83–84 for aggregate components, 239, 241–242 on exceptions, 202 factories vs.,

INDEX 345

Dispose Pattern for, 249–260finalizers for, 248–249

Unsealed classes, 164–165UrtCop. See FxCopUsability

framework design for, 12–13naming conventions for, 33of scenario-driven framework

design, 17–19Usage guidelines, 305–309

VValidation, argument, 152–155Value equality, 224Value types

choice between class, struct, 74–76enum design, 91–101equality operators on, 232explicit interface member

implementation, 111–115groupings of types, 67–68IEquatable<T> on, 222interface design and, 87interface for polymorphic hierarchy,

82Object.Equals on, 224, 225struct design, 89–90

Valuesto enums, 100–101of properties, 116property change notification events

and, 125Varargs methods, 160VB. See Visual BasicVick, Paul

.NET Framework unification, 11case sensitivity, 41framework design, 8framework with multiple languages,

16layered architecture principle, 29low barrier to entry principle, 20parameters in VB, 155

Virtual members

callbacks vs., 166–168constructor design and, 129–130explicit interface member

implementation and, 114–115extensibility with, 168–170member overloading, 108–109sealing, 176–177Template Method Pattern and,

267–269unsealed classes and, 164

Visibility, 240, 241Visible instance fields, 300Visual Basic (VB)

case sensitivity and, 41framework design for programmers,

8layered architecture, 29libraries, design of, 9low barrier to entry, 20parameters in, 155Rapid Application Development, 10word choice conventions, 43

Visual Basic.NETattribute in, 211finally blocks of, 194usability problems of, 13

Visual Studioaggregate component integration

with, 237FxCop rules and, 286Intellisense, 71

Visual Studio Designers, 243

WWell-designed framework, 3–6Win32

CloseHandle, 181failure reporting of, 179framework design of, 9

Windows, Microsoft, 10–11Word choice

FxCop rules for, 286–287naming conventions for, 42–43

Wrapping, 195–197

Abrams_IDX.fm Page 345 Friday, August 19, 2005 7:15 PM

Page 20: Index [ptgmedia.pearsoncmg.com] · 2009. 6. 9. · INDEX 331 Constructors abstract class design, 83–84 for aggregate components, 239, 241–242 on exceptions, 202 factories vs.,

INDEX346

XXML. See Extensible Markup LanguageXMLDataDocument, 231XmlReader, 230–231

ZZero, value of

flag enum design, 99–100on simple enum, 95

Abrams_IDX.fm Page 346 Friday, August 19, 2005 7:15 PM


Recommended