Index

#include directives, 129

A

abbreviations, 284

access protection, subverting, 141

Account, 120, 364

ActionEvent class, 145

ACTIOReportFor, 108

Adapt Parameter, 142, 326-329

adapting parameters, 326-329

addElement, 160

AddEmployeeCmd, 279

getBody, 280

write method, 274

adding features. See features, adding

AGGController, 339-341

algorithms for changing legacy code, 18

breaking dependencies, 19

finding test points, 19

identifying change points, 18

refactoring, 20

writing tests, 19

aliased parameters, getting classes into test harnesses, 133-136

analyzing effects, 167-168

API calls. See also libraries

restructuring, 199-201, 203-207

skinning and wrapping, 205-207

application architecture, preserving, 215-216

conversation concepts, 224

Naked CRC, 220-223

telling story of system, 216-220

architecture of system, preserving, 215-216

conversation concepts, 224

Naked CRC, 220-223

telling story of system, 216-220

automated refactoring

monster methods, 294-296

tests, 46-47

automated tests, 185-186

characterization tests, 186-189

for classes, 189-190

heuristic for writing, 195

targeted testing, 190-194

B

Beck, Kent, 48, 220

behavior, 5

preserving, 7

behavior of code. See characterization tests 188

BindName method, 337

BondRegistry, 367

Brant, John, 45

Break Out Method Object, 137, 330-336

monster methods, 304

breaking

dependencies, 19-25, 79-85, 135

Interception Points, 174-182

breaking up classes, 183

bug finding

versus characterization tests, 188

when to fix bugs, 190

bugs, fixing in software, 4-6

build dependencies, breaking, 80-85

buildMartSheet, 42

bulleted methods, 290

C

C macro preprocessor, testing procedural code, 234-236

C++, 127

compilers, 127

effect reasoning tools, 166

Template Redefinition, 410

calls, 348-349

CCAImage, 139-140

cell.Recalculate, 40

change points, identifying, 18

changing software. See software, changing characterization tests, 151, 157, 186-189

for classes, 189-190

heuristic for writing, 195

targeted testing, 190-194

characters, writing null characters, 272

classes

Account, 364

ActionEvent, 145

AddEmployeeCmd, 279

AGGController, 339

big classes, 247

extracting classes from, 268

problems with, 245

refactoring, 246

responsibilities. See responsibilities

breaking up, 183

CCAImage, 139-140

characterization tests, 189-190

ClassReader, 155

Command, 281-282

Coordinate, 165-166

CppClass, 156

ExternalRouter, 373

extracting, 268

to current class first monster methods, 306

fakeConnection, 110

getting into test harnesses

aliased parameters, 133-136

global dependency, 118-126

hidden dependency, 113-116

huge parameter lists, 116-118

include dependencies, 127-130

parameters, 106-113, 130-132

IndustrialFacility, 135

instances, 122

interfaces, extracting, 80

LoginCommand. See LoginCommand

ModelNode, 357

naming conventions, 227-228

once dilemma, 198

OriginationPermit, 134-135

Packet, 345

PaydayTransaction, 362

ProductionModelNode, 358

RuleParser, 250

Scheduler, 128

SymbolSource, 150

test harnesses, parameters, 113

testing subclasses, 227, 390

ClassReader, 155

code

editing. See editing code

effect propagation, 164-165

modularity, 29

preparing for changes, 157-163

test code versus production code, 110

code reuse

avoiding library dependencies, 197-198

restructuring API calls, 199-207

collaborating fakes, mock objects, 27-28

Command class, 281-282

write method, 277

writeBody method, 285

Command/Query Separation, 147-149

commandChar variable, 276-277

CommoditySelectionPanel, 296

compilers

C++, 127

editing code, 315-316

compiling Scheduler, 129

completing definitions, 337-338

Composed Method (testing changes), 69

concrete class dependencies versus interface dependencies, 84

const keyword, 164

constructors, Parameterize Constructor, 379-382

conventions, class naming conventions, 227-228

Coordinate class, 165-166

coordinates, 165

coupling count, 301-302

Cover and Modify, 9

Coverage, 13

CppClass, 156

CppUnitLite, 50-52

CRC (Class, Responsibility, and Collaborations), Naked CRC, 220-223

CreditMaster, 107-108

CreditValidator, 107

Cunningham, Ward, 220

cursors, 116

D

data type conversion errors, 193-194

db_update, 36

debugging. See bug finding

decisions, looking for, 251

declarations, 154

decorator pattern, 72-73

Definition Completion, 337-338

definitions, completing, 337-338

dejection, overcoming, 319-321

delegating instance methods, 369-376

deleting unused code, 213

dependencies, 16, 18, 21

avoiding, 197-198

breaking. See breaking; dependency-breaking techniques

getting classes into test harnesses, 113-116

gleaning from monster methods, 303

global dependencies, getting classes into test harnesses, 118-126

include dependencies, getting classes into test harnesses, 127-130

in procedural code, avoiding, 236-239

Push Down Dependency, 392-395

restructuring API calls, 199-207

dependency-breaking techniques

Adapt Parameter, 326-329

Break Out Method Object, 330-336

Definition Completion, 337-338

Encapsulate Global References, 339-344

Expose Static Method, 345-347

Extract and Override Call, 348-349

Extract and Override Factory Method, 350-351

Extract and Override Getter, 352-355

Extract Implementer, 356-361

Extract Interface, 362-368

Introduce Instance Delegator, 369-371

Introduce Static Setter, 372-376

Link Substitution, 377-378

Parameterize Constructor, 379-382

Parameterize Methods, 383-384

Primitivize Parameter, 385-387

Pull Up Feature, 388-391

Push Down Dependency, 392-395

Replace Function with Function Pointer, 396-398

Replace Global Reference with Getter, 399-400

Subclass and Override Method, 401-403

Supersede Instance Variable, 404-407

Template Redefinition, 408-411

Text Redefinition, 412-413

design, improving software design. See refactoring

directories, locations for test code, 228-229

draw(), Renderer, 332

duplication, 269-271

removing, 93-94, 272-287

renaming classes, 284

E

Edit and Pray, 9

Edit and Pray programming, 246

editing code

compilers, 315-316

hyperaware editing, 310

Pair Programming, 316

preserving signatures, 312-314

single-goal editing, 311-312

effect analysis

IDE support for, 152

learning from, 167-168

effect propagation, 163-165

preventing, 165

effect reasoning, 152-157

tools for, 165-167

effect sketches, 155, 254

pinch points, 108-184

effect sketches, simplifying, 168-171

effects, encapsulation, 171

effects of change, understanding, 212

Elements, 158

elements

addElement, 160

generateIndex, 159

enabling points, 36

Encapsulate Global References, 239, 315-316, 339-344

encapsulating global references, 339-344

encapsulation, effects, 171

encapsulation boundaries, pinch points as, 182-183

error localization, 12

errors

changing software, 14-18

type conversion, 193-194

evaluate method, 248

exceptions, throwing, 89

execution time, 12

Expose Static Method, 137, 330, 345-347

exposing static methods, 345-347

ExternalRouter, 373

Extract and Override Call, 348-349

Extract and Override Factory Method, 116, 350-351

Extract and Override Getter, 352, 354-355

Extract Implementer, 71, 74, 80-82, 85, 117, 131, 356-361

Extract Interface, 17, 71, 74, 80, 85, 112-114, 117, 131, 135, 326, 333, 362-368

Extract Method (refactoring), 415-419

extracting

calls, 348-349

classes, 268

to current class first, monster methods 306

factory method, 350-351

getters, 352-355

implementers, 356-361

interfaces, 362-368

monster methods, 301-302

small pieces, monster methods, 306

extracting interfaces, 80

extracting methods, 212

refactoring tools, 195

Responsibility-Based Extraction, 206-207

targeted testing, 190-194

extractions, redoing in monster methods, 307

F

factory method, 350-351

failing test cases, writing, 88-91

fake objects, 23-27

distilling fakes, 27

tests, 26

FakeConnection class, 110

fakes

collaborating mock objects, 27-28

distilling, 27

fake objects. See fake objects

feature sketches, 252-254

features, adding, 87

with programming by difference, 94-104

with test-driven development (TDD), 88-94

FeeCalculator, 259

feedback, 11

testing. See testing

feedback lag time, effect on length of time for changes, 78-79

file inclusion, testing procedural code, 234-236

finding

sequences, monster methods, 305-306

test points, 19

FIT (Framework for Integration), 53

fit.Fixture, 37

fit.Parse, 37

Fitnesse, 53

fixing bugs in software, 3-4

formConnection method, 404

formStyles method, 349

Fowler, Martin, 325

Framework for Integration Tests

(FIT), 53

Frameworks, 118

global dependency, 118-126

function pointers

replacing, 396-398

testing procedural code, 238-239

functional changes, 310

functions

PostReceiveError, 31

replacing with function pointers, 396-398

run(), 132

send message, 114

SequenceHasGapFor, 386

substituting, 377-378

G

Gamma, Erich, 48

GDIBrush, 333-334

GenerateIndex, 158-162

elements, 159

generating indexes, 158

getBalance, 120

getBalancePoint(), 152

getBody, AddEmployeeCmd, 280

getDeadTime, 389

getDeclarationCount(), 153

getElement, 160, 163

getElementCount, 160, 163

getInstance method, 120

getInterface, 154

getKSRStreams, 142

getLastLine(), 27

getName, 153

getters

extracting, 352-355

lazy getters, 354

overriding, 352-355

replacing global references, 399-400

getValidationPercent, 106, 110

Gleaning Dependencies, monster methods, 303

global dependency, getting classes into test harnesses, 118-126

global references

encapsulating, 339-344

replacing with getters, 399-400

graphics libraries, link seams, 39

grouping methods, 249

H

hidden methods, 250

getting methods into test harnesses, 138-141

hierarchies, permits, 134

higher-level testing, 14, 173-174

Interception Points, 174-182

HttpFileCollection, 141

HttpPostedFile objects, 141

HttpServletRequest, 327

hyperaware editing, 310

I

IDE, support for effect analysis, 152

identifying change points, 18

implementers, extracting, 356-361

include dependencies, getting classes into test harnesses, 127-130

independence, removing duplication, 285

indexes, generating, 158

IndustrialFacility, 135

inheritance, programming by difference, 94-104

InMemoryDirectory, 158, 161

instances

classes, 122

Introduce Instance Delegator, 369-376

Supersede Instance Variable, 404-407

testing, 123

PermitRepository, 121

Interception Points, 174-182

Interface Segregation Principle (ISP), 263

interfaces, 132

dependencies versus concrete class dependencies, 84

extracting, 80, 362-368

naming, 364

ParameterSource, 327

segregating, 264

internal relationships, looking for, 251

Introduce Instance Delegator, 369-371

Introduce Sensing Variable, 298-301

Introduce Static Setter, 122, 126, 341, 372-376

ISP (Interface Segregation Principle), 263

J

Jeffries, Ron, 221

JUnit, 49-50, 217

K

keywords

const, 164

mutable, 167

knobs, 287

L

lag time, effect on length of time for changes, 78-79

language features, getting methods into test harnesses, 141-144

lazy getters, 354

Lean on the Compiler, 125, 143, 315

legacy code, changing algorithms, 18

breaking dependencies, 19

finding test points, 19

identifying change points, 18

refactoring, 20

writing tests, 19

legacy systems versus well-maintained systems, understanding of code, 77

length of time for changes, 77

breaking dependencies, 79-85

reasons for, 77-79

test harness usage, 57-59

Sprout Class, 63-67

Sprout Method, 59-63

Wrap Class, 71-76

Wrap Method, 67-70

libraries. See also API calls

dependencies, avoiding, 197-198

graphics libraries, link

seams, 39

mock object libraries, 47

Link Seam, testing procedural code, 233-234

link seams, 36-40

Link Substitution, 342, 377-378

Liskov substitution principle (LSP) violation, 101

listing markup for understanding code, 211-212

LoginCommand, 278

write method, 272-273

LSP (Liskov substitution principle) violation, 101

M

macro preprocessor, testing procedural code, 234-236

mail service, 113-114

manual refactoring, monster methods, 297

Break Out Method

Object, 304

extracting, 301-302

Gleaning Dependencies, 303

Introduce Sensing Variable, 298-301

marking up listings for understanding code, 211-212

MessageForwarder, 401

method objects, breaking out, 330-336

from monster methods, 304

method use rule, 189

methods

ACTIOReportFor, 108

BindName, 337

draw(), Renderer, 332

effects of change, understanding, 212

evaluate, 248

Extract Method (refactoring), 415-419

extracting, 212

formConnection method, 404

formStyles, 349

getBalancePoint(), 152

getBody, AddEmployeeCmd, 280

getDeclarationCount(), 153

getElement, 160, 163

getElementCount, 160, 163

getInstance, 120

getInterface, 154

getKSRStreams, 142

getting into test harnesses

hidden methods, 138-141

language features, 141-144

side effects, 144-150

getValidationPercent, 110

grouping methods, 249

hidden methods, 138-141, 250

lazy getters, 354

monster methods. See monster methods

non-virtual methods, 367

Parameterize Method, 383-384

performCommand, 147-149

populate, 326

private methods, testing for, 138

public methods, 138

readToken, 157

recalculate, 306

recordError, 366

resetForTesting(), 122

Responsibility-Based Extraction, 206-207

restricted override dilemma, 198

RFDIReportFor, 108

scan(), 23-25

setUp, 50

showLine, 25

snap(), 139

Sprout Method, 246

static methods, exposing, 345-347

Subclass and Override Method, 401-403

suspend frame, 339

targeted testing, 190-194

tearDown, 375

testEmpty, 49

understanding structure

of, 211

update, 296

updateBalance, 370

validate, 136, 345

write, 273-275

AddEmployeeCmd, 274

Command class, 277

LoginCommand, 272-273

writeBody, 281

Command class, 285

writing tests for, 137

migrating to object orientation, 239-244

Mike Hill, 51

mock objects, 27-28, 47

ModelNode class, 357

modularity, 29

monster methods, 289

automated refactoring, 294-296

bulleted methods, 290

extracting small pieces, 306

extracting to current class first, 306

finding sequences, 305-306

manual refactoring. See manual refactoring

redoing extractions, 307

skeletonize methods, 304-305

snarled methods, 292-294

morale, increasing, 319-321

mutable, 167

N

Naked CRC, 220-223

naming, 356

interfaces, 364

naming conventions

abbreviations, 284

classes, 227-228

new constructors, 381

non-virtual methods, 367

normalized hierarchy, 103

null characters, 272

Null Object Pattern, 112

NullEmployee, 112

nulls, 111-112

NUnit, 52

O

object orientation, migrating to, 239-244

object seams, 33, 40-44, 239, 369

objects

creating, 130

fake objects, 23-27

distilling, 27

tests, 26

HttpFileCollection, 141

HttpPostedFile, 141

mail service, 113-114

mock objects, 27-28, 47

once dilemma, 198

OO languages, C++, 127

Opdyke, Bill, 45

open/closed principle, 287

optimization, changing software, 6

OriginationPermit, 134-135

Orthogonality, 285

overriding

calls, 348-349

factory method, 350-351

getters, 352-355

overwhelming feelings, overcoming, 319-321

P

Packet class, 345

PageLayout, 348

Pair Programming, 316

paper view, 402

parameter lists, getting classes into test harnesses, 116-118

Parameterize Constructor, 114-116, 126, 171, 242, 341, 379-382

Parameterize Method, 341, 383-384

parameters

adapting, 326-329

aliased parameters, 133-136

getting classes into test harnesses, 106-113, 130-132

Parameterize Constructor, 379-382

Parameterize Method, 383-384

Primitivize Parameter, 385-387

ParameterSource, 327

Pass Null, 62, 111-112, 131

passing nulls 112

patterns

Null Object Pattern, 112

Singleton Design Pattern, 372

PaydayTransaction class, 362

performCommand, 147-149

Permit, hierarchies, 134

PermitRepository, 120-125

pinch points, 80

as encapsulation boundaries, 182-183

testing with, 180-184

pointers. See function pointers

populate method, 326

PostReceiveError, 31, 44

preparing for changes to code, 157-163

preprocessing seams, 33-36, 130

Preserve Signatures, 70, 240, 312-314, 331

preserving

behavior, 7

signatures, 312-314

preventing effect propagation, 165

primary responsibilities, looking for, 260

Primitivize Parameter, 17, 385-387

principles, open/closed principle, 287

private methods, testing for, 138

problems with big classes, 245

procedural code, testing, 231-232

with C macro preprocessor, 234-36

with file inclusion, 234-236

function pointers, 238-239

with Link Seam, 233-234

migrating to object orientation, 239-244

Test-Driven Development (TDD), 236-238

production code versus test code, 110

ProductionModelNode, 358

programming, rediscovering fun in, 319-321

programming by difference, 94-104

propagating effects. See effect propagation

public methods, 138

Pull Up Feature, 388-391

Push Down Dependency, 392-395

R

readToken method, 157

reasoning

effect reasoning, 152-157

tools for, 165-167

reasoning forward, 157-163

reasoning forward, 157-163

Recalculate, 40-42

recalculate method, 306

recordError, 366

redefining

templates, 408-411

text, 412-413

redoing extractions, monster methods, 307

refactoring, 5, 20, 45, 415

automated refactoring

monster methods, 294-296

and tests, 46-47

big classes, 246

Extract Method, 415-419

manual refactoring, monster methods, 297-301

scratch refactoring, 264

refactoring tools, 45-46, 195

scratch refactoring for understanding code, 212-213

Refactoring: Improving the Design of Existing Code (Fowler), 415

references, Encapsulate Global References, 339-344

regression testing, 10-11

relationships, looking for internal relationships, 251

removing duplication, 93-94, 272-287

renaming classes, 284

renderer, draw(), 332

Replace Function with Function Pointer, 396-398

Replace Global Reference with Getter, 399-400

replacing

functions with function pointers, 396-398

global references with getters, 399-400

Reservation, 256-257

resetForTesting(), 122

responsibilities, 249

decisions, looking for decisions that can change, 251

grouping methods, 249

hidden methods, 250

internal relationships, 251-253

ISP (Interface Segregation Principle), 263

looking for primary

responsibility, 260

primary responsibilities, 260

scratch factoring, 264

segregating interfaces, 264

separating, 211

strategy for dealing with, 265

tactics for dealing with, 266-268

Responsibility-Based Extraction, 206-207

restricted override dilemma, 198

return values, effect propagation 163

RFDIReportFor, 108

RGHConnections, 107-109

risks of changing software, 7-8

Roberts, Don, 45

RuleParser class, 250

run(), 132

S

safety nets, 9

scan(), 23-25

Scheduler, 128-129, 391

compiling, 129

SchedulerDisplay, 130

SchedulingTask, 131-132

scratch refactoring, 264

for understanding code, 212-213

seams, 30-33

enabling points, 36

link seams, 36-40

object seams, 33, 40-44

preprocessing seams, 33-36

segregating interfaces, 264

send message function, 114

sensing, 21-22

sensing variables, 301, 304

separating responsibilities, 211

separation, 21-22

SequenceHasGapFor, 386

sequences, finding in monster methods, 305-306

setSnapRegion, 140

setTestingInstance, 121-123

setUp method, 50

showLine, 25

side effects, getting methods into test harnesses, 144-150

signatures, preserving, 312-314

simplifying

effect sketches, 168-171

system architecture, 216-220

single responsibility principle (SRP), 99, 246-248, 260-262

single-goal editing, 311-312

Singleton Design Pattern, 120, 372

skeletonize methods, 304-305

sketches

effect sketches, simplifying, 168-171

for understanding code, 210-211

Reservation, 255

skinning and wrapping API calls, 205-207

Smalltalk, 45

snap(), 139

snarled methods, 292-294

software

behavior, 5

changing, 3-8

risks of, 7-8

test coverings, 14-18

software vise, 10

Sprout Class (testing changes), 63-67

Sprout Method (testing changes) 59-63, 246

SRP (single responsibility principle), 246-248, 260-262

static cling, 369

static methods, 346

exposing, 345-347

strategies

for dealing with responsibilities, 265

for monster methods

extracting small pieces, 306

extracting to current class

first, 306

finding sequences, 305-306

redoing extractions, 307

skeletonize methods, 304-305

Subclass and Override Method, 112, 125, 136, 401-403

Subclass to Override, 148

subclasses

Subclass and Override Method, 401-403

testing subclasses, 390

subclassing, programming by difference, 95-96

substituting functions, 377-378

subverting access protection, 141

Supercede Instance Variable, 117-118, 404-407

suspend frame method, 339

SymbolSource, 150

system architecture, preserving, 215-216

conversation concepts, 224

Naked CRC, 220-223

telling story of system, 216-220

T

tactics for dealing with responsibilities, 266-268

targeted testing, 190-194

TDD (Test-Driven Development), 20, 88-94, 236-238

tearDown method 375

techniques, dependency-breaking techniques. See dependency-breaking techniques

Template Redefinition, 408-411

templates, redefining, 408-411

temporal coupling, 67

test code versus production code, 110

test harnesses, 12

adding features, 87

and length of time for changes, 57-59

Sprout Class, 63-67

Sprout Method, 59-63

Wrap Class, 71-76

Wrap Method, 67-70

breaking dependencies, 79-85

FIT, 53

Fitnesse, 53

getting classes into

aliased parameters, 133-136

global dependency, 118-126

hidden dependency, 113-116

huge parameter lists, 116-118

include dependencies, 127-130

parameters, 106-112, 130-132

getting methods into

hidden methods, 138-141

language features, 141-144

side effects, 144-150

test points, finding 19

Test-Driven Development (TDD), 20, 60, 64, 70, 88-94, 236-238, 310

testEmpty method, 49

TESTING, 36

testing, 9

around changes, 14-18

higher-level testing, 14

instances, 121-123

for private methods, 138

procedural code, 231-232

function pointers, 238-239

migrating to object orientation, 239-244

Test-Driven Development (TDD), 236-238

with C macro preprocessor, 234-236

with file inclusion, 234-236

with Link Seam, 233-234

regression testing, 10-11

test harnesses, 12

unit testing, 12-14

unit-testing harnesses, 48

CppUnitLite, 50-52

JUnit, 49-50

NUnit, 52

testing subclasses, 227, 390

TestingPager, 405

tests

automated refactoring, 46-47

automated tests, 185-186

characterization tests, 186-190, 195

targeted testing, 190-194

Characterization Tests, 151, 157

class naming conventions, 227-228

directory locations for, 228-229

fake objects, 26

higher-level tests, 173-174

Interception Points, 174-182

method use rule, 189

unit tests, pinch point traps, 184

writing, 19

for methods, 137

text, redefining, 412-413

Text Redefinition, 412-413

throwing exceptions, 89

time for changes, length of. See length of time for changes

tools

for effect reasoning, 165-167

refactoring tools, 45-46

unit-testing harnesses, 48

CppUnitLite, 50-52

JUnit, 49-50

NUnit, 52

TransactionLog, 366

TransactionManager, 350

TransactionRecorder, 365

type conversion errors, 193-194

U

UML notation, 221

understanding code, 209

deleting unused code, 213

effect on length of time for changes, 77-78

listing markup, 211-212

scratch refactoring, 212-213

sketches, 210-211

unit testing, 12-14

unit tests, pinch point traps, 184

unit-testing harnesses, 48

CppUnitLite, 50-52

JUnit, 49-50

NUnit, 52

unused code, deleting, 213

update method, 296

updateBalance, 370

V

validate method, 136, 345

variables

commandChar, 276-277

effects of change, 212

Reservation class, 253

sensing variables, 301

Supersede Instance Variable, 404-407

vise, 10

W

well-maintained systems versus legacy systems, understanding of code, 77

WorkflowEngine, 350

Wrap Class (testing changes), 71-76

Wrap Method (testing changes), 67-70

wrapping, skinning and wrapping API calls, 205-207

write method, 273-275

AddEmployeeCmd, 274

Command class, 277

LoginCommand, 272-273

writeBody method, 281

Command class, 285

writing

null characters, 272

tests, 19

for methods, 137

X

xUnit, 48, 52