Smalltalk, Objects, and Design Table of Contents


Acknowledgments xi

 

 

 

 

 

Preface xiii

 

 

 

 

1

Objects 1

 

 

1.1

Objects 1

 

 

1.2

Examples of Smalltalk messages (telegrams) 5

 

 

1.3

Pitfall: the effect versus the return 6

 

 

1.4

Why objects matter 7

 

 

1.5

Recap: objects 8

 

 

1.6

Exercise: warmup (the image) 9

 

 

1.7

Commentary: perspectives on objects 9

 

 

 

 

2

Classes and inheritance 11

 

 

2.1

Classes 11

 

 

2.2

The word "class" 13

 

 

2.3

Inheritance 13

 

 

2.4

Terminology 18

 

 

2.5

Exercise: hierarchies 21

 

 

2.6

Solution and discussion: Aggregation hierarchies 21

 

 

2.7

Example: aggregation plus inheritance 22

 

 

2.8

Syntaxes for inheritance 23

 

 

2.9

Example: inheritance in Smalltalk 24

 

 

2.10

Exercise: building a class hierarchy 26

 

 

2.11

Commentary: what is object-oriented programming? 27

 

 

2.12

Commentary: other languages 29

 

 

2.13

Commentary: history 30

 

 

 

 

3

Smalltalk introduction 32

 

 

3.1

Elementary objects 32

 

 

3.2

Messages and their precedences 33

 

 

3.3

Pitfalls: basic Smalltalk gotchas 34

 

 

3.4

Examples 36

 

 

3.5

Exercise: a hypothetical method 37

 

 

3.6

Solution and discussion 38

 

 

3.7

Kinds of variables 39

 

 

3.8

Pitfall: variables [[pi]] objects 40

 

 

3.9

Classes are objects 40

 

 

3.10

Control flow 42

 

 

3.11

Commentary: metaclasses 43

 

 

 

 

4

Exercises -- Foundations 44

 

 

4.1

Precautions 44

 

 

4.2

Finding things in Smalltalk 46

 

 

4.3

Elements of Smalltalk 48

 

 

4.4

Smalltalk's debugger 57

 

 

4.5

Provocations 59

 

 

 

 

5

Abstract classes 61

 

 

5.1

Exercise in object-oriented design 62

 

 

5.2

Solution and discussion 62

 

 

5.3

Pure virtual (subclassResponsibility) methods 64

 

 

5.4

Exercise: discovering pure virtuals 65

 

 

5.5

Solution and discussion 65

 

 

5.6

Ensuring no instances 65

 

 

5.7

Concrete behavior in abstract classes 67

 

 

5.8

Summary: methods in abstract classes 68

 

 

 

 

6

Containers and other indispensable ideas 69

 

 

6.1

Heterogeneity and homogeneity 70

 

 

6.2

Exercise: heterogeneity and homogeneity 71

 

 

6.3

Exercise: dictionaries 72

 

 

6.4

Preparatory exercise: identity versus equality 73

 

 

6.5

Identity dictionaries 74

 

 

6.6

Exercise: identity dictionaries 75

 

 

6.7

Overriding equality 75

 

 

6.8

Exercise: anomaly of the disappearing element 76

 

 

6.9

Exercise: excursion into Streams 77

 

 

6.10

Containers versus aggregations 78

 

 

6.11

Shallow and deep copying 79

 

 

6.12

Commentary: value and reference semantics 80

 

 

6.13

Commentary: containers in C++ 81

 

 

 

 

7

CRC cards 82

 

 

7.1

Design exercise 83

 

 

7.2

Solution and discussion 84

 

 

7.3

Common questions and answers 87

 

 

7.4

Commentary: analysis, design, and implementation 88

 

 

 

 

8

Exercises--Implementing a design 91

 

 

8.1

Create the classes 91

 

 

8.2

A test case 91

 

 

8.3

Write "new" methods 92

 

 

8.4

Write instance methods 92

 

 

8.5

Test your solution 93

 

 

8.6

Engineering discipline 94

 

 

8.7

A minor variation 94

 

 

8.8

"Private" methods 94

 

 

8.9

Commentary: getters and setters 95

 

 

8.10

Summary 96

 

 

 

 

9

When (not) to inherit 97

 

 

9.1

Historical background 97

 

 

9.2

Inverting hierarchies 98

 

 

9.3

Buy or inherit? 99

 

 

9.4

Exercise 100

 

 

9.5

Solution and discussion 100

 

 

9.6

Conclusions 102

 

 

9.7

Commentary: multiple inheritance 103

 

 

 

 

10

Use cases and dynamic relationships 105

 

 

10.1

Interaction diagrams 105

 

 

10.2

Exercise 108

 

 

10.3

Solution and discussion 109

 

 

10.4

Use cases and interaction diagrams in analysis and design 110

 

 

10.5

Limitations 112

 

 

10.6

Summary 113

 

 

10.7

Commentary: historical note 114

 

 

 

 

11

The venerable model-view-controller 115

 

 

11.1

Model-view-controller example 115

 

 

11.2

Exercise 118

 

 

11.3

How MVC works 119

 

 

11.4

Exercise: the original dependency mechanism 121

 

 

11.5

MVC: benefits and difficulties 122

 

 

11.6

What's become of MVC? 124

 

 

 

 

12

Building windows 127

 

 

12.1

What you need to know about Motif 128

 

 

12.2

Widget resources 130

 

 

12.3

Excursion: pool dictionaries 131

 

 

12.4

Exercise: a first window 133

 

 

12.5

Exercise: a window for the account balance 134

 

 

12.6

Exercise: a window for the transaction log 135

 

 

12.7

Exercise: a window containing both widgets 136

 

 

12.8

Assessment: building windows 136

 

 

12.9

Callbacks and events 137

 

 

12.10

Preparation 138

 

 

12.11

Exercise: mouse event handling 138

 

 

12.12

Challenging exercise: dynamic updates 139

 

 

12.13

Summary 140

 

 

 

 

13

Designing the UI: a brief tour 142

 

 

13.1

User interfaces 142

 

 

13.2

Elementary examples 143

 

 

13.3

Coherent conceptual models 144

 

 

13.4

Metaphor 146

 

 

13.5

Magic 148

 

 

13.6

Exercise: design a user interface 151

 

 

13.7

Discussion of your results 152

 

 

13.8

Isomorphism 155

 

 

13.9

Summary 156

 

 

 

 

14

Polymorphism 158

 

 

14.1

Dynamic binding 158

 

 

14.2

Dynamic binding enables . . . polymorphism 159

 

 

14.3

A word on terminology 161

 

 

14.4

Exercise: polymorphism 162

 

 

14.5

Solutions and discussion 162

 

 

14.6

Exercise: Smalltalk's if-less-ness 163

 

 

14.7

Solution 163

 

 

14.8

Summary tip 165

 

 

14.9

Commentary: performance 165

 

 

14.10

Commentary: Smalltalk, C++, and type-checking 166

 

 

14.11

Commentary: the tomato in the mailbox 169

 

 

14.12

Commentary: multi-methods 170

 

 

 

 

15

Practicing polymorphism 173

 

 

15.1

Design exercise I: a shape editor 173

 

 

15.2

Solution and discussion 174

 

 

15.3

Design exercise II: undo and redo 176

 

 

15.4

Solution and discussion 177

 

 

15.5

Implementing undo 179

 

 

15.6

Summary 180

 

 

 

 

16

How object-oriented languages work 181

 

 

16.1

Virtual machines 181

 

 

16.2

Method lookup 183

 

 

16.3

Memory management: a brief history of garbage collection 187

 

 

16.4

The irony of garbage collection 191

 

 

16.5

Commentary: why not garbage collect C++? 192

 

 

16.6

Smalltalk deviates from uniformity 193

 

 

16.7

Exercises 195

 

 

16.8

Summary 197

 

 

 

 

17

Two kinds of inheritance 198

 

 

17.1

Beauty and the beast 198

 

 

17.2

Why types matter: polymorphism 200

 

 

17.3

Commentary: an aside on subsets 201

 

 

17.4

Commentary: what does "consistency" mean? 201

 

 

17.5

Consistency and Smalltalk 207

 

 

17.6

Exercise: Smalltalk's container "types" 208

 

 

17.7

Solution and discussion 208

 

 

17.8

Exercise: Smalltalk's container "classes" 210

 

 

17.9

Solution and discussion 210

 

 

17.10

Summary 211

 

 

17.11

Commentary: standardizing Smalltalk 212

 

 

 

 

18

Design patterns 213

 

 

18.1

Notation 214

 

 

18.2

Smart container (aka collection-worker) 215

 

 

18.3

Reification 216

 

 

18.4

Command 217

 

 

18.5

Factory method 219

 

 

18.6

Objects from records 220

 

 

18.7

Proxies and ghosts, I 224

 

 

18.8

Proxies and ghosts, II 226

 

 

18.9

Dependency 228

 

 

18.10

Solitaire (aka singleton) 230

 

 

18.11

Duet (aka pas de deux, double dispatch) 231

 

 

18.12

Lawyer (aka object handler) 233

 

 

18.13

Composite 235

 

 

18.14

Visitor 236

 

 

18.15

Conclusion 239

 

 

18.16

Commentary: history 240

 

 

 

 

19

Frameworks (one hearty example) 242

 

 

19.1

Problems 243

 

 

19.2

Materialization 244

 

 

19.3

Managing object identity 246

 

 

19.4

Searching (filtering) 248

 

 

19.5

Updating 251

 

 

19.6

Summary 252

 

 

19.7

Commentary: varieties of brokers 254

 

 

19.8

Commentary: buying outdoes inheriting (sometimes) 255

20

Metaclasses 257

 

 

20.1

Facts about metaclasses 257

 

 

20.2

Inheritance 258

 

 

20.3

Method new 259

 

 

20.4

The full picture 260

 

 

20.5

Recapitulation 262

 

 

20.6

Exercises 263

 

 

 

 

21

Why developing software is still hard 264

 

 

21.1

Misconceptions 264

 

 

21.2

Where projects go awry: borders 267

 

 

21.3

Characteristics of successful projects 269

 

 

21.4

An optimistic conclusion 272

 

 

 

 

 

Appendix: Some differences between dialects 275

 

 

 

 

 

References 277

 

 

 

 

 

Index 283


Go to the preface.

Go to the book's main web page.

Return home.