Smalltalk and Object Orientation
Total Page:16
File Type:pdf, Size:1020Kb
Smalltalk and Object Orientation: An Introduction John Hunt JayDee Technology Ltd, Hartham Park Corsham, Wiltshire , SN13 0RP United Kingdom Email: [email protected] http://www.jaydeetechnology.co.uk Preface This book was originally written to support an introductory course in Object Orientation through the medium of Smalltalk (and VisualWorks in particular). However, it can be used as a book to teach the reader Smalltalk, to introduce object orientation as well as present object oriented design and analysis. It takes as its basic premise that most Computer Scientists / Software Engineers learn best by doing rather than from theoretical notes. The chapters therefore attempt to intro duce concepts by getting you the reader to do things, rather than by extensive theoretical discussions. This means that these chapters take a hands -on approach to the subject and assume that the student/reader has a suitable Smalltalk environment available to them. The chapters are listed below and are divided into six parts. The reader is advised to work through Parts 1 and 3 thoroughly in order to gain a detailed understanding of object orientation. Part 2 then provides an introduction to the Smalltalk environment and language. Other chapters may then be dipped into as required. For example, if the reader wishes to hone their Smalltalk skills then the chapters in Part 4 would be useful. However, if at that point they wish to get on and discover the deligh ts of graphical user interfaces in Smalltalk, then Part 5 could be read next. Part 6 presents some more advances subjects such as metaclasses and concurrency which are not required for straight forward Smalltalk development. Content Summary Part 1: Introduction to Object Orientation Chapter 1: Introduction to Object Orientation The aim of this chapter is to provide an introduction to the range of concepts and ideas which make up object technology. It presents the background which led to the acceptance of object orientation as a mainstream technology and discusses the pedigree of the Smalltalk language. Chapter 2: Elements of Object Orientation This chapter provides a more formal definition of the terminology introduced in Chapter 1. It also considers the advantages and disadvantages of an object oriented approach compared to more traditional procedural approaches. Chapter 3: Constructing an Object Oriented System A typical problem for many people when being introduced to a new approach is that they understand the terminology and the concepts but not how to use them. This chapter aims to alleviate this problem by presenting a detailed worked example of the way in which an object oriented system may be designed and constructed. It does so without reference t o any particular language so that language issues should not confuse the discussion. Part 2: The Smalltalk Language Chapter 4: An Introduction to Smalltalk The aim of this chapter is to provide some background on the history of Smalltalk and the developm ent environments which are available to support it (such as the VisualWorks system). It also considers some of the tools the reader will encounter. Chapter 5: A Little Smalltalk This chapter presents a number of other tools such as the inspectors and debu ggers available in VisualWorks. It then uses a worked example to help the user to use some of the development tools available. Chapter 6: Smalltalk Building Blocks The chapter introduces the basic elements the Smalltalk language, it discusses the concep t of classes in Smalltalk and how they are defined. 2 Chapter 7: Smalltalk Constructs This chapter presents further details of the Smalltalk language including the representation and use of numbers, strings and characters. Chapter 8: An Example Smalltalk Class In Chapter 7, the reader is presented with a detailed worked example of software development in Smalltalk. This example presents a very simple class definition which uses only those concepts which have been introduced at this stage. The intention is t o illustrate how the constructs and language elements can be combined in a real (if simple) program. Chapter 9: Control and Iteration This chapter introduces how control and iteration are achieved in Smalltalk. To do this a number of concepts which are un ique to Smalltalk are also discussed (such as the block object). To simplify this process for the reader, equivalent C constructs are illustrated beside Smalltalk constructs (where they exist). Chapter 10: The Collection Classes This chapter discusses pro bably the most widely used class hierarchy in Smalltalk; the collection class hierarchy. It presents the hierarchy in general and some of the commonly used collection classes. It also illustrates how these classes can be used to construct other collection style classes such as queues and stacks. Chapter 11: Further Collection Classes This chapter concludes the examination of the collection classes available in Smalltalk and presents an application constructed using these classes. Chapter 12: An Object Oriented Organizer This chapter presents a detailed example application constructed using the collection classes. The Organizer is intended as an electronic personal Organizer. It therefore possesses an address book, a diary (or appointments section) and a section for notes. The remainder of this chapter describes one way of implementing such an Organizer. Chapter 13: Streams and Files This chapter discusses the second most used class hierarchy in Smalltalk; the Stream classes. The Stream classes are used (amongst other things) for accessing files. The Binary Object Streaming Service for storing objects in files is also discussed. Chapter 14: The Magnitude Class Hierarchy This chapter considers the magnitude class and those classes which inherit from it. This includes the Number hierarchy. The classes Character, Time and Date are also considered. Chapter 15: Some More Tools of the Trade This chapter introduces the use of breakpoints in Smalltalk, the purpose of the change list file and how to file in and file out Smalltalk code. Part 3: Object Oriented Design Chapter 16: Object Oriented Analysis and Design This chapter introduces the concepts of object oriented analysis and design. It reviews a number of the more popular techniques such as OOA, OMT, Objector y and Booch. It also briefly considers the unification of the OMT and Booch notations. Chapter 17: The Unified Modeling Language The Unified Modeling Language (or UML for short) is a third generation object -oriented modeling language which adapts and exte nds the published notations used in the Booch, OMT and Objectory methods. It is intended that the UML will form a single, common, widely usable modeling language for 3 a range of object oriented design methods (including Booch, Objectory and OMT). It is also intended that it should be applicable in a wide range of applications and domains. This chapter (and the next) summarize the UML notation. Chapter 18: UML: Dynamic Modeling and Deployment This chapter continues the description of the Unified Modeling Lan guage (UML) started in the last chapter. Chapter 19: The Object Modeling Technique This chapter, and the next, discuss the influential design method referred to as the Object Modeling Technique (OMT). It summarizes the main phases of OMT using the UML not ation. One extension to OMT is the introduction of use case models from Objectory to improve the requirements analysis process. This is motivated by the inclusion of use case diagrams in the UML. Chapter 20: More Object Modeling Technique This chapter continues the description of the Object Modeling Technique (OMT). Chapter 21: Frameworks and Patterns for Object Oriented Design The aim of this chapter is to introduce the concept of frameworks and in particular patterns. This is still a relatively new idea within Object Orientation, but one which is growing in popularity at an incredible rate. Part 4: Testing and Style Chapter 22: Testing Object Oriented Systems Object oriented systems may make code easier to reuse and may be supported by object oriented analysis and design methods, but they do not guarantee that the code is correct. This chapter looks at some of the issues behind testing object oriented systems. Chapter 23: Method and Class Testing The last chapter discussed the problems facing the test er of an object oriented system (and in particular a Smalltalk system). This chapter considers current best practice in testing object oriented systems. Chapter 24: Smalltalk Style Guidelines The aim of this chapter is the promotion of readable, understan dable, concise and efficient Smalltalk code. A point to note is that style guidelines for languages such as Pascal do not cover many of the issues which are important in Smalltalk. As in any programming language there are a number of acknowledged bad pract ices which are not specific to Smalltalk, for example the use of global variables! Such guidelines are familiar to programmers of most languages. This section will therefore try to concentrate on those style issues which are specific to Smalltalk. Part 5: Graphical Interfaces in Smalltalk Chapter 25: The Perform and Dependency Mechanisms In this chapter the use of perform to provide an alternative method for sending messages is considered. This is followed by a practical discussion of the dependency mecha nism. This includes what the dependency mechanism is, why you might want to use, how you construct a dependency and the effect that it has. Chapter 26: The Model-View-Controller Architecture The Model-View-Controller (or MVC) architecture is the basis upon which user interfaces are constructed in Smalltalk. The architecture separates out the application from the user interface. This chapter introduces the MVC architecture and explains the motivation behind it. A worked example is presented to illustrate the theoretical description. Chapter 27: Graphic User Interface Construction Tools 4 The user interface construction facilities in Smalltalk are subject to the widest variation between dialects of any aspect of the language.