A Little Smalltalk
نویسنده
چکیده
Superclasses We did not discuss the classes Collection, KeyedCollection, SequenceableCollection, or ArrayedCollection in the last section, even though they were listed as forms of "collection" in the beginning of this chapter. These classes, along with such classes as Boolean, Magnitude, or Number, are what are known as abstract superclasses. Instances of abstract superclasses are seldom useful by themselves, but the classes are important in providing methods that can be inherited by subclasses. For example, while it is legal in Smalltalk to say: x ~ Collection new and the resulting variable x will indeed be an instance of class Collection, the object is not particularly useful. It has no insertion or deletion protocol, for example. An instance of class Set, however, is very useful, and the messages defined in class Collection are important in providing functionality to objects of this class and to other subclasses of class Collection. The selection and design of abstract superclasses is one of the more important arts in Smalltalk programming. For example, if one were designing a system to manipulate banking accounts, a class Account might be a useful abstract superclass for classes CheckingAccount and SavingsAccount. The actions specific to the individual types of accounts would be in the subclasses, whereas any common behavior, such as the actions necessary for opening and closing an account or querying the balance, might be implemented in the superclass. EXERCISES Basic Classes 33 1. Suppose you created a new instance of the class UndefinedObject, as follows: I~UndefinedObject new How does i respond to print? To isNil or notNil? To the object comparison message = = with nil ? Is i nil? List facts to support your answer. 2. Note that the messages arcSin and arcCos produce an object of type Radian and not of type Float. Furthermore, only objects of type Radian respond to sin and cos. An alternative would have been to eliminate the class Radian and to permit all objects of class Float to respond to the messages sin and cos. Discuss the advantages and disadvantages of these two different arrangements. 3. Suppose you have a Bag containing numbers. How would you go about producing an instance of the class List containing the numbers listed in sorted order? 4. What is the class of Class? what is the superclasss of Class? 5. Many times, two or more different sequences of messages to collections will have the same effect. In each of the following, describe a sequence of messages that will have the same effect ,\S the indicated message. a) implement reject: in terms of select: b) implement size in terms of inject:into: c) implement includes: in terms of inject:into:.
منابع مشابه
A browser for incremental programming
Much of the elegance and power of Smalltalk comes from its programming environment and tools. First introduced more than 20 years ago, the Smalltalk browser enables programmers to “home in” on particular methods using a hierarchy of manually-defined classifications. By its nature, this classification scheme says a lot about the desired state of the code, but little about the actual state of the...
متن کاملThe Larch / Smalltalk Interface Speci cation
Object-oriented programming languages, such as Smalltalk, help one to build reusable program modules. The reuse of program modules requires adequate documentation | formal or informal. Larch/Smalltalk is a formal speciication language for specifying such reusable Smalltalk modules. Larch/Smalltalk rmly separates speciication from implementation. In Larch/Smalltalk the unit of speciication is an...
متن کاملThe Design and Implementation of Distributed Smalltalk the Design and Implementation of Distributed Smalltalk
Distributed Smalltalk (DS) is an implementation of Smalltalk that allows objects on diierent machines to send and respond to messages. It also provides some capability for sharing objects among users. The distributed aspects of the system are largely user transparent and preserve the reactive quality of Smalltalk objects. Distributed Smalltalk is currently operational on a network of Sun workst...
متن کاملA Model of Refactoring Tool Use
For the most part, refactoring tools have changed little since the Smalltalk Refactoring Browser. By continuing to mimic the Refactoring Browser’s user interface, the community of tool builders may be not find new user interfaces that help programmers do their job more effectively. In this position paper, I put forward a general model of how programmers use Refactoring Browser-like tools. I arg...
متن کاملProgramming with ObjVlisp Metaclasses in Smalltalk-80
A b s t r a c t This paper discusses the introduction of explicit metaclasses à la ObjVlisp into the Smalltalk-80 language. The rigidity of Smalltalk metaclass architecture motivated this work. Consequently we decided to implement the ObjVlisp model into the standard Smalltalk-80 system. The resulting combination defines the Classtalk platform. This platform provides a full-size environment to ...
متن کاملSmalltalk: Overview and Implementation Issues
In respect to points 1-3, Smalltalk is similar to recently developed object-oriented languages such as Java or C#. However, it includes a GUI which contains a development environment and debugging facilities; even the GUI itself can be modified and analyzed using Smalltalk. Smalltalk implementations include the virtual machine (VM) and the virtual image (VI). The virtual machine is hardware/ope...
متن کاملذخیره در منابع من
با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید
عنوان ژورنال:
دوره شماره
صفحات -
تاریخ انتشار 2003