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 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 .................................................................................................................................................
Recommended publications
  • The Early History of Smalltalk
    The Early History of Smalltalk http://www.accesscom.com/~darius/EarlyHistoryS... The Early History of Smalltalk Alan C. Kay Apple Computer [email protected]# Permission to copy without fee all or part of this material is granted provided that the copies are not made or distributed for direct commercial advantage, the ACM copyright notice and the title of the publication and its date appear, and notice is given that copying is by permission of the Association for Computing Machinery. To copy otherwise, or to republish, requires a fee and/or specific permission. HOPL-II/4/93/MA, USA © 1993 ACM 0-89791-571-2/93/0004/0069...$1.50 Abstract Most ideas come from previous ideas. The sixties, particularly in the ARPA community, gave rise to a host of notions about "human-computer symbiosis" through interactive time-shared computers, graphics screens and pointing devices. Advanced computer languages were invented to simulate complex systems such as oil refineries and semi-intelligent behavior. The soon-to- follow paradigm shift of modern personal computing, overlapping window interfaces, and object-oriented design came from seeing the work of the sixties as something more than a "better old thing." This is, more than a better way: to do mainframe computing; for end-users to invoke functionality; to make data structures more abstract. Instead the promise of exponential growth in computing/$/volume demanded that the sixties be regarded as "almost a new thing" and to find out what the actual "new things" might be. For example, one would compute with a handheld "Dynabook" in a way that would not be possible on a shared mainframe; millions of potential users meant that the user interface would have to become a learning environment along the lines of Montessori and Bruner; and needs for large scope, reduction in complexity, and end-user literacy would require that data and control structures be done away with in favor of a more biological scheme of protected universal cells interacting only through messages that could mimic any desired behavior.
    [Show full text]
  • Process Synchronisation Background (1)
    Process Synchronisation Background (1) Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms to ensure the orderly execution of cooperating processes Producer Consumer Background (2) Race condition count++ could be implemented as register1 = count register1 = register1 + 1 count = register1 count- - could be implemented as register2 = count register2 = register2 - 1 count = register2 Consider this execution interleaving with ―count = 5‖ initially: S0: producer execute register1 = count {register1 = 5} S1: producer execute register1 = register1 + 1 {register1 = 6} S2: consumer execute register2 = count {register2 = 5} S3: consumer execute register2 = register2 - 1 {register2 = 4} S4: producer execute count = register1 {count = 6 } S5: consumer execute count = register2 {count = 4} Solution: ensure that only one process at a time can manipulate variable count Avoid interference between changes Critical Section Problem Critical section: a segment of code in which a process may be changing Process structure common variables ◦ Only one process is allowed to be executing in its critical section at any moment in time Critical section problem: design a protocol for process cooperation Requirements for a solution ◦ Mutual exclusion ◦ Progress ◦ Bounded waiting No assumption can be made about the relative speed of processes Handling critical sections in OS ◦ Pre-emptive kernels (real-time programming, more responsive) Linux from 2.6, Solaris, IRIX ◦ Non-pre-emptive kernels (free from race conditions) Windows XP, Windows 2000, traditional UNIX kernel, Linux prior 2.6 Peterson’s Solution Two process solution Process Pi ◦ Mutual exclusion is preserved? ◦ The progress requirements is satisfied? ◦ The bounded-waiting requirement is met? Assumption: LOAD and STORE instructions are atomic, i.e.
    [Show full text]
  • Gnu Smalltalk Library Reference Version 3.2.5 24 November 2017
    gnu Smalltalk Library Reference Version 3.2.5 24 November 2017 by Paolo Bonzini Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled \GNU Free Documentation License". 1 3 1 Base classes 1.1 Tree Classes documented in this manual are boldfaced. Autoload Object Behavior ClassDescription Class Metaclass BlockClosure Boolean False True CObject CAggregate CArray CPtr CString CCallable CCallbackDescriptor CFunctionDescriptor CCompound CStruct CUnion CScalar CChar CDouble CFloat CInt CLong CLongDouble CLongLong CShort CSmalltalk CUChar CByte CBoolean CUInt CULong CULongLong CUShort ContextPart 4 GNU Smalltalk Library Reference BlockContext MethodContext Continuation CType CPtrCType CArrayCType CScalarCType CStringCType Delay Directory DLD DumperProxy AlternativeObjectProxy NullProxy VersionableObjectProxy PluggableProxy SingletonProxy DynamicVariable Exception Error ArithmeticError ZeroDivide MessageNotUnderstood SystemExceptions.InvalidValue SystemExceptions.EmptyCollection SystemExceptions.InvalidArgument SystemExceptions.AlreadyDefined SystemExceptions.ArgumentOutOfRange SystemExceptions.IndexOutOfRange SystemExceptions.InvalidSize SystemExceptions.NotFound SystemExceptions.PackageNotAvailable SystemExceptions.InvalidProcessState SystemExceptions.InvalidState
    [Show full text]
  • APPLYING MODEL-VIEW-CONTROLLER (MVC) in DESIGN and DEVELOPMENT of INFORMATION SYSTEMS an Example of Smart Assistive Script Breakdown in an E-Business Application
    APPLYING MODEL-VIEW-CONTROLLER (MVC) IN DESIGN AND DEVELOPMENT OF INFORMATION SYSTEMS An Example of Smart Assistive Script Breakdown in an e-Business Application Andreas Holzinger, Karl Heinz Struggl Institute of Information Systems and Computer Media (IICM), TU Graz, Graz, Austria Matjaž Debevc Faculty of Electrical Engineering and Computer Science, University of Maribor, Maribor, Slovenia Keywords: Information Systems, Software Design Patterns, Model-view-controller (MVC), Script Breakdown, Film Production. Abstract: Information systems are supporting professionals in all areas of e-Business. In this paper we concentrate on our experiences in the design and development of information systems for the use in film production processes. Professionals working in this area are neither computer experts, nor interested in spending much time for information systems. Consequently, to provide a useful, useable and enjoyable application the system must be extremely suited to the requirements and demands of those professionals. One of the most important tasks at the beginning of a film production is to break down the movie script into its elements and aspects, and create a solid estimate of production costs based on the resulting breakdown data. Several film production software applications provide interfaces to support this task. However, most attempts suffer from numerous usability deficiencies. As a result, many film producers still use script printouts and textmarkers to highlight script elements, and transfer the data manually into their film management software. This paper presents a novel approach for unobtrusive and efficient script breakdown using a new way of breaking down text into its relevant elements. We demonstrate how the implementation of this interface benefits from employing the Model-View-Controller (MVC) as underlying software design paradigm in terms of both software development confidence and user satisfaction.
    [Show full text]
  • Software Architecture: the Next Step for Object Technology (PANEL)
    Software Architecture: The Next Step for Object Technology (PANEL) Bruce Anderson, University of ESSPX (moderator) Mary Shaw, Carnegie-Mellon University Larry Best, American Management Systems Kent Beck, First Class Software What is the next step for you? Progress comes Abstract from taking aware steps, but what steps are those? Architectures are the structuring paradigms, styles They could be in attempting to discover and and patterns that make up our software systems. catalogue architectures; creating awareness of this They are important in many ways: they allow us to level of product envisioning; doing design more talk usefully about systems without talking about consciously; finding ways of describing systems; their detail; a knowledge of them gives us design consolidating legacy code; abandoning legacy code; choices; attention to this level can make systems and making new software lifecycles. families of systems have the non-functional What is the next step for the community? Are there properties we want, especially changeability. ways to work that go beyond projects and Each panelist will address the following issues: companies? Will there be focus on the community, l What is architecture? which suggests cooperation, learning, divergence l What is the value you have had so far from and empowerment; or on the marketplace, which this concept? suggests competition, confidentiality, convergence l What is the next step for you? and dependence? l What is the next step for the community? 2 Mary Shaw 1 Background Software architecture is concerned with the What is architecture? We all have experience of organization of software systems: the selection of systems of great conceptual clarity and integrity.
    [Show full text]
  • Learning Javascript Design Patterns
    Learning JavaScript Design Patterns Addy Osmani Beijing • Cambridge • Farnham • Köln • Sebastopol • Tokyo Learning JavaScript Design Patterns by Addy Osmani Copyright © 2012 Addy Osmani. All rights reserved. Revision History for the : 2012-05-01 Early release revision 1 See http://oreilly.com/catalog/errata.csp?isbn=9781449331818 for release details. ISBN: 978-1-449-33181-8 1335906805 Table of Contents Preface ..................................................................... ix 1. Introduction ........................................................... 1 2. What is a Pattern? ...................................................... 3 We already use patterns everyday 4 3. 'Pattern'-ity Testing, Proto-Patterns & The Rule Of Three ...................... 7 4. The Structure Of A Design Pattern ......................................... 9 5. Writing Design Patterns ................................................. 11 6. Anti-Patterns ......................................................... 13 7. Categories Of Design Pattern ............................................ 15 Creational Design Patterns 15 Structural Design Patterns 16 Behavioral Design Patterns 16 8. Design Pattern Categorization ........................................... 17 A brief note on classes 17 9. JavaScript Design Patterns .............................................. 21 The Creational Pattern 22 The Constructor Pattern 23 Basic Constructors 23 Constructors With Prototypes 24 The Singleton Pattern 24 The Module Pattern 27 iii Modules 27 Object Literals 27 The Module Pattern
    [Show full text]
  • The Great Methodologies Debate: Part 1
    ACCESS TO THE EXPERTS The Journal of Information Technology Management December 2001 Vol. 14, No. 12 The Great Methodologies Debate: Part 1 Resolved “Today, a new debate rages: agile software Traditional methodologists development versus rigorous software are a bunch of process- development.” dependent stick-in-the-muds who’d rather produce flawless Jim Highsmith, Guest Editor documentation than a working system that meets business needs. Opening Statement Jim Highsmith 2 Rebuttal Lightweight, er, “agile” Agile Can Scale: Inventing and Reinventing methodologists are a bunch of SCRUM in Five Companies glorified hackers who are going to be in for a heck of a surprise Jeff Sutherland 5 when they try to scale up their “toys” into enterprise-level software. Agile Versus Traditional: Make Love, Not War! Robert L. Glass 12 Business Intelligence Methodologies: Agile with Rigor? Larissa T. Moss 19 Agility with the RUP Philippe Kruchten 27 Extreme Requirements Engineering Larry Wagner 34 Exclusion, Assumptions, and Misinterpretation: Foes of Collaboration Lou Russell 39 Opening Statement by Jim Highsmith In the early 1980s, I participated in rigorous software development. others be able to understand the one round of methodology debate. Agile approaches (Extreme similarities and differences and be Structured analysis and design Programming, Crystal Methods, able to apply the right mix to their champions such as Tom DeMarco, Lean Development, Feature-Driven own organization. Both the SEI and Ed Yourdon, and Tim Lister were Development, Adaptive Software Rational have made wonderful on one side of the debate, while Development, SCRUM, and contributions to software develop- data-driven design aficionados like Dynamic Systems Development ment, but it is important to Ken Orr, Jean-Dominique Warnier, Methodology) populate one camp.
    [Show full text]
  • Smahtalk Kernel Language Fv1anual
    This document is for Xerox internal use only SmaHtalk Kernel Language fv1anual BY Larry Tesler SEPTEMBER 1977 Smalltalk is a programming rang'uage that deals with objects. Every object has its own data. Objects communicate by sending and receiving messages according to simple. protocols. Objects are grouped into classes. The objects of a class are called its instances. Each class specifies the protocols its instances will know as well as the methods they will use to respond to messages they receive.· The standard facilities of the Small talk system include i/o protocols for disk, display, keyboard, mouse, and Ethernet; basic data structures such as numbers, strings, arrays, and dictionaries; basic control structures such as loops and processes; program editing, compiling, and debugging; text editing, illustration, music. animation, and information storage and retrieval. Smalltalk applications include education, personal computing, and systems research. This interim reference manual covers the semantics and the present syntax of the Smalltalk kernel language. It is assumed that the reader has seen Smalltalk in operation and has programmed computers in Algol-like languages. Familiarity with LISP, Simula, and/or Smallta!k-72 should be helpful but is not necessary. System operation is described in the memo, Browsing and Error Analysis, available under separate cover from the Learning Research Group, Systems Science Laboratory. XEROX PALO ALTO RESEARCH CENTER 3333 Coyote Hill Road / Palo J\lto / California 94304 This document is for Xerox internal use only Discla inler The Smalltalk kernel system is not yet ready for general release. \Ve ask that you do not copy and distribute either the manual or the system at this time.
    [Show full text]
  • Hopscotch: Towards User Interface Composition Vassili Bykov Cadence Design Systems, 2655 Seely Ave, San Jose, CA 95134
    Hopscotch: Towards User Interface Composition Vassili Bykov Cadence Design Systems, 2655 Seely Ave, San Jose, CA 95134 Abstract Hopscotch is the application framework and development environment of Newspeak, a new programming language and platform inspired by Smalltalk, Self and Beta. Hopscotch avoids a number of design limitations and shortcomings of traditional UIs and UI frameworks by favoring an interaction model and implementing a framework architecture that enable composition of interfaces. This paper discusses the deficiencies of the traditional approach, provides an overview of the Hopscotch alternative and analyses how it improves upon the status quo. 1. Introduction Hopscotch are attributable to its revised interaction and navigation model as much as to the underlying Newspeak [1] is a programming language and framework architecture. For this reason, this paper platform being developed by a team led by Gilad pays equal attention to the compositional frame- Bracha at Cadence Design Systems, Inc. The sys- work architecture and to the changes in the inter- tem is currently hosted inside Squeak [2], a descen- action model of Hopscotch compared to more tradi- dent of Smalltalk-80 [3]. Smalltalk, along with Self tional development environments. [4] and Beta [5], is also among the most important influences on the design of the Newspeak language. 2. Traditional Interface Construction This paper focuses on Hopscotch, the applica- tion framework of Newspeak and the Newspeak The art of devising forms to be filled in depends IDE implemented concurrently with the frame- on three elements: obscurity, lack of space, and work. The framework and the IDE allow easy nav- the heaviest penalties for failure.
    [Show full text]
  • Design Patterns in Ocaml
    Design Patterns in OCaml Antonio Vicente [email protected] Earl Wagner [email protected] Abstract The GOF Design Patterns book is an important piece of any professional programmer's library. These patterns are generally considered to be an indication of good design and development practices. By giving an implementation of these patterns in OCaml we expected to better understand the importance of OCaml's advanced language features and provide other developers with an implementation of these familiar concepts in order to reduce the effort required to learn this language. As in the case of Smalltalk and Scheme+GLOS, OCaml's higher order features allows for simple elegant implementation of some of the patterns while others were much harder due to the OCaml's restrictive type system. 1 Contents 1 Background and Motivation 3 2 Results and Evaluation 3 3 Lessons Learned and Conclusions 4 4 Creational Patterns 5 4.1 Abstract Factory . 5 4.2 Builder . 6 4.3 Factory Method . 6 4.4 Prototype . 7 4.5 Singleton . 8 5 Structural Patterns 8 5.1 Adapter . 8 5.2 Bridge . 8 5.3 Composite . 8 5.4 Decorator . 9 5.5 Facade . 10 5.6 Flyweight . 10 5.7 Proxy . 10 6 Behavior Patterns 11 6.1 Chain of Responsibility . 11 6.2 Command . 12 6.3 Interpreter . 13 6.4 Iterator . 13 6.5 Mediator . 13 6.6 Memento . 13 6.7 Observer . 13 6.8 State . 14 6.9 Strategy . 15 6.10 Template Method . 15 6.11 Visitor . 15 7 References 18 2 1 Background and Motivation Throughout this course we have seen many examples of methodologies and tools that can be used to reduce the burden of working in a software project.
    [Show full text]
  • Extreme Programming from Wikipedia, the Free Encyclopedia
    Create account Log in Article Talk Read Edit View history Search Extreme programming From Wikipedia, the free encyclopedia Main page Extreme programming (XP) is a software development methodology which is Contents intended to improve software quality and responsiveness to changing customer Featured content requirements. As a type of agile software development,[1][2][3] it advocates frequent Current events "releases" in short development cycles, which is intended to improve productivity Random article and introduce checkpoints at which new customer requirements can be adopted. Donate to Wikipedia Wikipedia store Other elements of extreme programming include: programming in pairs or doing Interaction extensive code review, unit testing of all code, avoiding programming of features Help until they are actually needed, a flat management structure, simplicity and clarity in About Wikipedia code, expecting changes in the customer's requirements as time passes and the Community portal problem is better understood, and frequent communication with the customer and Recent changes among programmers.[2][3][4] The methodology takes its name from the idea that the Contact page Planning and feedback loops in beneficial elements of traditional software engineering practices are taken to extreme programming. Tools "extreme" levels. As an example, code reviews are considered a beneficial What links here practice; taken to the extreme, code can be reviewed continuously, i.e. the practice Related changes Software development of pair programming. Upload file process Special pages Critics have noted several potential drawbacks,[5] including problems with Core activities Permanent link unstable requirements, no documented compromises of user conflicts, and a Requirements · Design · Construction · Testing · Debugging · Deployment · Page information lack of an overall design specification or document.
    [Show full text]
  • Automatic Graph Drawing Lecture 15 Early HCI @Apple/Xerox
    Inf-GraphDraw: Automatic Graph Drawing Lecture 15 Early HCI @Apple/Xerox Reinhard von Hanxleden [email protected] 1 [Wikipedia] • One of the first highly successful mass- produced microcomputer products • 5–6 millions produced from 1977 to 1993 • Designed to look like a home appliance • It’s success caused IBM to build the PC • Influenced by Breakout • Visicalc, earliest spreadsheet, first ran on Apple IIe 1981: Xerox Star • Officially named Xerox 8010 Information System • First commercial system to incorporate various technologies that have since become standard in personal computers: • Bitmapped display, window-based graphical user interface • Icons, folders, mouse (two-button) • Ethernet networking, file servers, print servers, and e- mail. • Sold with software based on Lisp (early functional/AI language) and Smalltalk (early OO language) [Wikipedia, Fair Use] Xerox Star Evolution of “Document” Icon Shape [Wikipedia, CC BY-SA 3.0] 1983: Apple Lisa [Wikipedia, CC BY-SA 2.0 fr] Apple Lisa • One of the first personal computers with a graphical user interface (GUI) • In 1982, Steve Jobs (Cofounder of Apple, with Steve Wozniak) was forced out of Lisa project, moved on into existing Macintosh project, and redefined Mac as cheaper, more usable version of Lisa • Lisa was challenged by relatively high price, insufficient SW library, unreliable floppy disks, and immediate release of Macintosh • Sold just about 10,000 units in two years • Introduced several advanced features that would not reappear on Mac or PC for many years Lisa Office
    [Show full text]