Index

| | = operator, 43, 4849

Abstract

behavior, promoting, 120123

classes, 117120, 235, 237

definition of, 54

superclass, creating, 117120

Abstractions

extracting, 150153

finding, 116129

insisting on, in writing inheritable code, 159

recognizing, 5455

separating from concretions, 123125

supporting, in intentional testing, 194

template method pattern, 125129

Across-class types, 86

Ad infinitum, 3

Aggregation, 183184

Agile, 810

Antipattern

definition of, 109, 111

recognizing, 158159

Argument-order dependencies, removing, 4651

defaults, explicitly defining, 4849

hashes for initialization arguments, using, 4648

multiparameter initialization, isolating, 4951

Automatic message delegation, 105106

Behaves-like-a relationships, 189

Behavior

acquired through inheritance, 105139

confirming, 233236

data structures, hiding, 2629

depending on, instead of data, 2429

instance variables, hiding, 2426

set of, 19

subclass, 233239

superclass, 234239

testing, 236239

Behavior Driven Development (BDD), 199, 213

Big Up Front Design (BUFD), 89

Booch, Grady, 188

Break-even point, 11

Bugs, finding, 193

Case statements that switch on class, 9698

kind_of? and is_a?, 97

responds_to?, 97

Category used in class, 111

Class. See also Single responsibility, classes with

abstract, 117120, 235, 237

avoiding dependent-laden, 55

bicycle, updating, 164165

case statements that switch on, 9698

code, organizing to allow for changes, 1617

concrete, 106109, 209

deciding what belongs in, 1617

decoupling, in writing inheritable code, 161

dependent-laden, avoiding, 55

grouping methods into, 16

references to (See Loosely coupled code, writing)

responsibilities isolated in, 3133

Ruby based vs. framework, 5354

type and category used in, 111

virtual, 61

Class-based OO languages, 1213

Class class, 14

Classical inheritance, 105106

Class of an object

ambiguity about, 9495

checking, 97, 111, 146

Class under test, removing private methods from, 214

Code. See also Inheritable code, writing; Inherited code, testing

concrete, writing, 147150

dependency injection to shape, 4142

depending on behavior instead of data, 2429

embracing change, writing, 2433

initialization, 121

loosely coupled, writing, 3951

open–closed, 185

organizing to allow for changes, 1617

putting its best (inter)face forward, writing, 7679

relying on duck typing, writing, 95100

single responsibility, enforcing, 2933

truths about, 53

Code arrangement technique, 184

Cohesion, 22

Command messages, 197, 216218

Compile/make cycle, 102, 103, 104

Compiler, 54, 101, 103104, 118

Composition

aggregation and, 183184

benefits of, 187

of bicycle, 180184

of bicycle of parts, 164168

consequences of, accepting, 187188

costs of, 187188

for has-a relationships, 183, 190

inheritance and, deciding between, 184190

manufacturing parts, 176180

objects combined with, 163190

of parts object, 168176

summary, 190

use of term, 183184

Concrete class, 106109, 209

Concretions

abstractions separated from, 123125

inheritance and, 106109

recognizing, 5455

writing, 147150

Context

independence, seeking, 7173

minimizing, 79

Contract, honoring, 159160

Costs

of composition, 187188

of duck typing, 85104

of inheritance, 185186

of testing, 191240

Coupling

decoupling classes in writing inheritable code, 161

decoupling subclasses using hook messages, 134138

between superclasses and subclasses, managing, 129138

understanding, 129134

Coupling between objects (CBO), 3738

C++, 102

Data

depending on behavior instead of, 2429

instance variables, hiding, 2426

structures, hiding, 2629

types, 12, 13

Decoupling

classes in writing inheritable code, 161

subclasses using hook messages, 134138

Defaults, explicitly defining, 4849

Delegation, 82, 183

Demeter. See Law of Demeter (LoD)

Demotion failure, 123

Dependencies

argument-order, removing, 4651

coupling between objects, 3738

direction of (See Dependency direction)

finding, 5557

injecting (See Dependency injection)

interfaces and, 6263

isolating, 4245

loosely coupled code, writing, 3951

managing, 3557

objects speaking for themselves, 147

other, 3839

recognizing, 37

removing unnecessary, 145147

reversing, 5153

scheduling duck type, discovering, 146147

summary, 57

understanding, 3639

Dependency direction

abstractions, recognizing, 5455

change in, likelihood of (See Likelihood of change)

choosing, 5357

concretions, recognizing, 5455

dependent-laden classes, avoiding, 55

finding, 5557

managing, 5157

reversing, 5153

Dependency injection

failure of, 60

in loosely coupled code, 3942

as roles, 208213

to shape code, 4142

using classes, 207208

Dependency Inversion Principle, 5

Dependent-laden classes, avoiding, 55

Design

act of, 711

definition of, 4

failure in, 78

judging, 1011

patterns, 67

principles, 56

problems solved by, 23

tools, 47

when to design, 810

Design decisions

deferring, 193

when to make, 2223

Design flaws, exposing, 194

Design patterns, 67

Design Patterns: Elements of Reusable Object-Oriented Software (Gamma, Helm, Johnson, and Vlissides), 6, 188

Design principles, 56

Design tools, 47

Documentation

of duck types, 98

of roles, testing used in, 212213

supplying, in testing, 193

Domain objects, 64, 83, 96, 199

Doubles, role tests to validate, 224229

DRY (Don’t Repeat Yourself ), 5, 24, 27, 28, 45, 50, 196

Duck types, 219229

defining, 85

documenting, 98

finding, 9094

hidden, recognizing, 9698

overlooking, 87

sharing between, 99

testing roles, 219224

trust in, placing, 98

using role tests to validate doubles, 224229

Duck typing

for behaves-like-a relationships, 189

case statements that switch on class, 9698

choosing ducks wisely, 99100

code that relies on, writing, 95100

consequences of, 9495

costs reduced with, 85104

dynamic typing and, 100104

fear of, conquering, 100104

problem, compounding, 8790

scheduling, discovering, 146147

static typing and, 100102

summary, 104

understanding, 8595

Dynamic typing

embracing, 102104

static typing vs., 100102

Embedded types of inheritance

finding, 111112

multiple, 109111

Explicit interfaces, creating, 7678

External messages, isolating, 4445

Extra responsibilities

extracted from methods, 2931

isolated in classes, 3133

Factories, 51

File data type, 12

Fixed-order arguments, 4651

Fixnum class, 13, 14

Fowler, Martin, 191

Framework class, vs. Ruby based class, 5354

Gamma, Erich, 6, 188

Gang of Four (Gof ), 6, 188

Gear inches, 2021

has-a relationships, 183, 190

vs. is-a relationships, 188189

Hashes used for initialization arguments, 4648

Helm, Richard, 6, 188

Hidden ducks

finding, 9094

recognizing, 9698

Highly cohesive class, 22

Hook messages, 134138

Hunt, Andy, 5

Incoming messages, testing, 200213

injecting dependencies as roles, 208213

injecting dependencies using classes, 207208

interfaces, deleting unused, 202203

isolating object under test, 205207

proving public interface, 203204

Inheritable code, writing, 158162

abstraction, insisting on, 159

antipatterns, recognizing, 158159

classes, preemptively decouple, 161

contract, honoring, 159160

shallow hierarchies, creating, 161162

template method pattern, using, 160

Inheritance

abstract class, finding, 116129

behavior acquired through, 105139

benefits of, 184185

choosing, 112114

classical, 105106

composition and, deciding between, 184190

concretions and, 106109

consequences of, accepting, 184186

costs of, 185186

embedded types of, 109112

family tree image of, 112

implying, 117

for is-a relationships, 188189

misapplying, 114116

multiple, 112

problem solved by, 112

recognizing where to use, 106114

relationships, drawing, 114

rules of, 117

single, 112

summary, 139

superclasses and subclasses, coupling between, 129138

Inherited code, testing, 229239

behavior, testing unique, 236239

inherited interface, specifying, 229232

subclass responsibilities, specifying, 233236

Inherited interface, specifying, 229232

Inheriting role behavior, 158

Initialization arguments, 4143

hashes used for, 4648

in isolation of instance creation, 4243

Initialization code, 121

Injection of dependencies. See Dependency injection

Instance variables, hiding, 2426

Intention, constructing, 6465

Intentional testing, 192200

Interface

inherited, specifying, 229232

Interfaces. See also Private interfaces; Public interfaces

code putting its best (inter)face forward, writing, 7679

defining, 6163

deleting unused, 202203

dependencies and, 6263

explicit, 7678

flexible, 5983

Law of Demeter and, 8083

responsibilities and, 6263

summary, 83

understanding, 5961

Interface Segregation Principle, 5

is_a?, 97

is-a relationships, 188189

vs. has-a relationships, 188189

Isolation

of dependencies, 4245

of external messages, 4445

of instance creation, 4243, 4244

of multiparameter initialization, 4951

of object under test, 205207

of responsibilities in classes, 3133

Java, 102, 118

JavaScript, 106

Johnson, Ralph, 6, 188

Keywords, 7778

kind_of?, 97

Law of Demeter (LoD), 5, 8083

defining Demeter, 80

Demeter project, 5, 80

listening to Demeter, 8283

violations, 8082

Likelihood of change, 5357

in embedded references to messages, 45

vs. number of dependents, 5557

understanding, 5354

Liskov, Barbara, 160

Liskov Substitution Principle (LSP), 5, 160, 230231, 237, 239

Loosely coupled code, writing, 3951

inject dependencies, 3942

isolate dependencies, 4245

remove argument-order dependencies, 4651

Managing dependencies, 3

Message, 15

Message chaining, 3839, 8083

Messages. See also Incoming messages, testing

applications, creating, 76

automatic message delegation, 105106

command, proving, 216218

delegating, 82

external, isolating, 4445

incoming, testing, 200213

likely to change, embedded references to, 45

message forwarding via classical inheritance, 112

objects discovered by, 7476

query, ignoring, 215216

testing outgoing, 215218

Metaprogramming, 102103

Methods

extra responsibilities extracted from, 2931

grouping into classes, 16

wrapper, 2425, 82

Methods, looking up, 154158

gross oversimplification, 154155

more accurate explanation, 155156

very nearly complete explanation, 156158

Metrics, 5, 1011

Meyer, Bertrand, 188

MiniTest, 200

Modules

definition of, 143

role behavior shared with, 141162

Monkey patching, 100

Multiparameter initialization, isolating, 4951

Multiple inheritance, 112

NASA Goddard Space Flight Center applications, 6

Nil, 4849, 113

NilClass, 113

Object class

ambiguity about, 9495

checking, 97, 111, 146

Object-Oriented Analysis and Design (Booch), 188

Object-oriented design (OOD), 114. See also Design

dependencies managed by, 3

masters of, 188

overview of, 1

Object-oriented languages, 1214

Object-oriented programming, 1114

object-oriented languages in, 1214

overview of, 11

procedural languages in, 12

Objects. See also Parts object

combined with composition, 163190

domain, 64, 83, 96, 199

messages used to discover, 7476

speaking for themselves, 147

trusting other, 7374

Object under test, 200, 202, 205207

Open–closed code, 185

Open-Closed Principle, 5, 185

Overridden methods, 115

Parts object

composition of, 168176

creating, 169172

creating PartsFactory, 177178

hierarchy, creating, 165168

leveraging PartsFactory, 178180

making more like array, 172176

manufacturing, 176180

Polymorphism, 95

Private interfaces

defining, 61, 62

depending on, caution in, 79

Private keyword, 7778

Private methods, testing, 213215

choosing, 214215

ignoring, 213214

removing from class under test, 214

Programing languages

statically or dynamically typed, 100104

syntax in, 118

type used in, 8586

Promotion failure, 122123

Protected keyword, 7778

Public interfaces

context independence, seeking, 7173

defining, 61, 62

example application: bicycle touring company, 6364

finding, 6376

intention, constructing, 6465

message-based application, creating, 76

messages used to discover objects, 7476

of others, honoring, 7879

proving, 203204

sequence diagrams, using, 6569

trusting other objects, 7374

“what” vs. “how,” importance of, 6971

Public keyword, 7778

Query messages, 196, 197, 215216

Refactoring

barriers to, reducing, 215

definition of, 191

in extracting extra responsibilities from methods, 2931

rule for, 123

strategies, deciding between, 122123

testing roles and, 220221, 226

in writing changeable code, 191192

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

Relationships, 188190

aggregation and, 183184

use composition for has-a relationships, 190

use duck types for behaves-like-a relationships, 189

use inheritance for is-a relationships, 188189

responds_to?, 97

Responsibilities, organizing, 143145

Responsibility-Driven Design (RDD), 22

Reversing dependency direction, 5153

Roles

concrete code, writing, 147150

finding, 142143

inheritable code, writing, 158162

injecting dependencies as, 208213

role behavior shared with modules, 141162

summary, 162

testing, in duck typing, 219224

testing to document, 212213

tests to validate doubles, 224229

understanding, 142158

Ruby based class vs. framework class, 5354

Runtime type errors, 101, 103104

Sequence diagrams, using, 6569

Shallow hierarchies in writing inheritable code, 161162

Single inheritance, 112

Single responsibility, classes with

benefits of, 31

code embracing change, writing, 2433

creating, 1723

design decisions, when to make, 2223

designing, 1534

determining, 22

enforcing, 2933

example application: bicycles and gears, 1721

extra responsibilities and, 2933

importance of, 21

real wheel, 3334

summary, 34

Single Responsibility Principle, 5

designing classes with, 1534

SOLID design principles, 5, 160

Source code repository, 59

Source lines of code (SLOC), 1011

Specializations, 117

Spike a problem, 198

Static typing

duck types and, subverting with, 100101

vs. dynamic typing, 100102

String class, 1314

String data type, 12, 13

String objects, 1314

Subclass behavior

confirming, 233234

testing, 236237

Subclasses

decoupling using hook messages, 134138

superclasses and, coupling between, 129138

Superclass behavior

confirming, 234236

testing, 237239

Superclasses

creating, 117120

subclasses and, coupling between, 129138

Syntax, 118

Technical debt, 11, 79

Template method pattern

implementing every, 127129

using, 125127

in writing inheritable code, 160

Test Driven Development (TDD), 199, 213

Testing

abstractions, supporting, 194

bugs, finding, 193

cost-effective, designing, 191240

creating test doubles, 210211

design decisions, deferring, 193

design flaws, exposing, 194

documentation, supplying, 193

duck types, 219229

incoming messages, 200213

inherited code, 229239

intentional testing, 192200

knowing how to test, 198200

knowing what to test, 194197

knowing when to test, 197198

knowing your intentions, 193194

outgoing messages, 215218

private methods, 213215

summary, 240

to document roles, 212213

Testing outgoing messages, 215218

command messages, proving, 216218

query messages, ignoring, 215216

Thomas, Dave, 5

Touch of Class: Learning to Program Well with Objects and Contracts (Meyer), 188

Train wreck, 80, 82, 83

TRUE code, 17

Types, 85. See also Duck typing

across-class, 86

static vs. dynamic, 100102

within-class, 63

Type used in class, 111

Unified Modeling Language (UML), 6566, 114

Use case, 64, 65, 66, 67, 69, 74

Variables, defining, 12

Virtual class, 61

Vlissides, Jon, 6, 188

“What” vs. “how,” importance of, 6971

Wilkerson, Brian, 22

Wirfs-Brock, Rebecca, 22

Within-class types, 63

Wrapper method, 2425, 82

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.240.119