Smalltalk Best Practice Patterns Volume 1: Coding Kent Beck First Class Software, Inc
Total Page:16
File Type:pdf, Size:1020Kb
Smalltalk Best Practice Patterns Volume 1: Coding Kent Beck First Class Software, Inc. Draft for comment only. Copyright (c) 1995, 1996, Kent Beck, All rights reserved. Please send comments to: voice: +1.408.338.4649 fax: +1.408.338.1115 email: [email protected] Coding Patterns page 1 of 147 9/30/2006 Table of Contents TABLE OF CONTENTS .......................................................................................................................................2 PREFACE ......................................................................................................................................................5 ACKNOWLEDGMENTS.............................................................................................................................7 INTRODUCTION .........................................................................................................................................8 CODING ............................................................................................................................................................9 Talking Programs........................................................................................................................................9 GOOD SOFTWARE...........................................................................................................................................11 STYLE.............................................................................................................................................................13 WHAT’S MISSING? .........................................................................................................................................14 ORGANIZATION ..............................................................................................................................................15 ADOPTION ......................................................................................................................................................16 PATTERNS..................................................................................................................................................17 WHY PATTERNS WORK..................................................................................................................................18 ROLE OF PATTERNS ........................................................................................................................................20 Reading......................................................................................................................................................20 Development..............................................................................................................................................20 Review .......................................................................................................................................................20 Documentation ..........................................................................................................................................20 Clean Up ...................................................................................................................................................20 FORMAT .........................................................................................................................................................21 BEHAVIOR .................................................................................................................................................22 METHODS.......................................................................................................................................................23 Composed Method ................................................................................................................................................. 24 Complete Creation Method .................................................................................................................................... 26 Creation Parameter Method ................................................................................................................................... 27 Conversion ............................................................................................................................................................. 28 Converter Method .................................................................................................................................................. 29 Converter Creation Method.................................................................................................................................... 30 Constructor Method ............................................................................................................................................... 31 Query Method ........................................................................................................................................................ 32 Comparing Method ................................................................................................................................................ 33 Execute Around Method ........................................................................................................................................ 34 Debug Printing Method.......................................................................................................................................... 35 MESSAGES......................................................................................................................................................36 Message.................................................................................................................................................................. 37 Choosing Message ................................................................................................................................................. 38 Decomposing Message........................................................................................................................................... 40 Intention Revealing Message ................................................................................................................................. 41 Intention Revealing Selector .................................................................................................................................. 42 Double Dispatch..................................................................................................................................................... 43 Send Back .............................................................................................................................................................. 45 Super ...................................................................................................................................................................... 47 Extending Super..................................................................................................................................................... 48 Modifying Super .................................................................................................................................................... 49 Delegation .............................................................................................................................................................. 50 Simple Delegation.................................................................................................................................................. 51 Self Delegation....................................................................................................................................................... 52 Pluggable Behavior ................................................................................................................................................ 54 Pluggable Selector.................................................................................................................................................. 55 Pluggable Block ..................................................................................................................................................... 56 Collecting Parameter.............................................................................................................................................. 57 Coding Patterns page 2 of 147 9/30/2006 STATE..........................................................................................................................................................59 INSTANCE VARIABLES....................................................................................................................................60 Common State........................................................................................................................................................ 61 Variable State......................................................................................................................................................... 62 Explicit Initialization.............................................................................................................................................. 63 Lazy Initialization .................................................................................................................................................