0. Intended Use
Smalltalk is a general purpose object-oriented programming language.
1. Basic Concepts
Smalltalk is uniformly object-oriented because everything that the Smalltalkprogrammer deals with is an object, from a number to an entire application.Within the context of Smalltalk, objects are implemented in code throughencapsulation and polymorphism.
Encapsulation is the approach used in Smalltalk to bundle everythingneeded into an object to preserve the integrity of the enclosed data. Thecode within an object performs operations on the objects internal data.Operations in Smalltalk are performed as the result of a messages beingsent to an object to execute a specific portion of its code (usually calleda "method"). For instance the statement "2 + 3" isa request to the receiver object "2" to perform the "+"method using the passed value "3." Intuitively it is assumedthat "2" is being asked to add "3" to itself and returna value of "5." The message "CorporateBudget updateWith:lastRevision" could be equally meaningful, but in both cases, howthe receiver object implements the operation is hidden from external viewthrough encapsulating the details within the object.
Polymorphism is the way that the Smalltalk language allows methods ofthe same name to have predictable and meaningful results in related instances,yet perform the operations differently to achieve the results. The method"updateWith," introduced in the prior paragraph, might reasonablyhave different code logic if it were encapsulated in the "ProjectBudget"object rather than the "CorporateBudget," but we can surmisethat if the method name reflects predictability, the effects should bethe same in either object.
Polymorphism is typically implemented in Smalltalk through the abstractionof the common properties of a group of objects into classes and hierarchicallysubclassing shared properties using inheritance-along with specializationof the subclass to define the differences.
Classes serve as templates because they define the instance variablesfor all the class instance variables and methods. The instance ofa class is created by sending a new message to the class which uniquelyidentifies the object instance and allocates space for its variable(s).
2. Objects
An object is an encapsulated software component made up of memory andoperations that creates a coherent programming entity. All objects arean instance of a class. Everything in Smalltalk is an object-from numbersto entire applications. Objects have public and private properties. Anobject's implementation details are private and are hidden from other objects.An object's public properties are its messages that make up its interface.The object's private properties are its variables. Interaction with anobject only occurs via these messages to its interface. All object instancesof a given class have a common message interface.
2.1 Operations
An operation is the action(s) taken by an object instance as resultof a message being received through the object's interface. Messages requestingoperations are addressed to specific recipient object instances, thus Smalltalkuses the "classical" object model and the method to execute inresponse to a message is determined by searching the object's class hierarchy.
2.2 requests
A request is act of sending a message to an object's interface withthe expectation that the object will perform a known operation that isassociated with the message.
2.3 messages
A Smalltalk message is a request to an object instance to perform anoperation. A message expression consists of a receiver, selector (messagename), and potentially some arguments. The selector must be mapped to amethod of the same name, encapsulated in the receiver object's class hierarchy.The arguments, if any, are used by the method to perform its operation.Message syntax occurs in one of three forms: unary, binary, and keyword.
Unary Messages have no arguments.
Example - Inventory deltaFromYesterday
In this case, Inventory is a variable identifying the receiver object,and deltaFromYesterday is the selector.
Binary Messages have one argument.
Example - 2+3
In this case, the object "2" is the receiver, "+"is the selector, and "3" is the argument.
Keyword Messages have one or more arguments. The selector in keywordmessages is composed of a keyword ahead of each argument. Keywords in messagesare identified by a trailing colon.
Example with two keywords - CorporateBudget updateWith: $3000 on: 'Travel'
In this case, CorporateBudget is a variable identifying the receiverobject, and updateWith: on: is the selector.
2.4 specification of behavioral semantics
Behavior in Smalltalk is defined by methods specified in classes whichare implemented as class instances and execution is triggered in thoseinstances by message requests.
A set of standard classes having common behavior across all Smalltalkimplementations is being proposed by the X3J20 Smalltalk Language Technicalcommittee. Many of them are already implemented by Smalltalk suppliers.These methods fall into categories where common behavior is inherited byobject instances, classes, collections, associations, streams, basic geometry,or file I/O.
2.5 methods
A method is the executable code rendered in the class and executed inthe context of an object instance. It defines how to perform an operationin the object instance. It is made up of a message pattern that is usedto match against incoming messages, temporary variables, and a sequenceof instructions. A method execution is triggered when message is receivedthat matches the methods' message pattern.
2.6 state
The state of a Smalltalk instance is represented by the values of itsinstance variables.
2.7 object lifetime
Smalltalk object instances are created with the "new" method.Each object instance is given a unique identifier called an object pointeror object reference. New classes are created by using the "subclass"method. The "new" and "subclass" methods are inheritedby almost all classes. Every instance object pointer is also associatedwith an object pointer of a class. Unlike the "new" and "subclass"methods, there are no specific methods that remove an object that is nolonger useful. Smalltalk objects are deleted when they are no longer reachable(garbage collected).
2.8 behavior/state grouping
Smalltalk uses the "classical" object model.
2.9 communication model
All communications within Smalltalk occur through messages between objectsand most Smalltalk implementations support a form of concurrency. For example,Smalltalk-80 provides for multiple independent processes, and semaphoresprovide the common mechanism for synchronizing the independent processes.
2.10 events
No specific mechanisms for handling events are built into the Smalltalklanguage, but "event handling" logic is commonly implementedin Smalltalk applications through its normal messaging techniques.
2.11 transition rules
3. Binding
Smalltalk performs run-time binding of messages to object methods. Seealso entry under 4. Polymorphism.
4. Polymorphism
Polymorphism is the way that the Smalltalk language allows methods ofsame name to have predictable and meaningful results in related instances,yet perform the operations differently to achieve similar results.
Smalltalk supports polymorphism by allowing methods defined in classesto be overridden with methods of the same name, but different logic, ina subsequent subclass. In addition, methods of the same name can be definedin a total different subclass hierarchy.
In the class hierarchy below, all of the lowest level classes are definedto accept the message "moveForward," but several different versionsare implemented as indicated by (MFn) in the diagram.The message sent to the instances of "Bus" or "Auto"uses the method defined in the "Motorized" class. The same methodis inherited by "Train" and "Motorcycle," but bothhave overridden the inherited method by defining a method with differentlogic using the same message pattern. All the others instances in the diagramhave the "moveForward" message pattern in their interface, butare not in the motorized inheritance chain. All of the "moveForward"methods function as you intuitively expect.
Transport Mechanism (mFabstract) /------------------ | --------------------\ Animal Powered Human Powered Motorized / (mF1) \ / \ / (mF5) \Buggy Wagon Land-based Water-based Public Private / \ / (mF4) \ / \ / \ Bike Skates Row Boat Canoe Bus Train Auto Motorcycle (mF2) (mF3) (mF6) (mF7)
5. Encapsulation
The approach used in Smalltalk is to encapsulate all objects, whethera complex as a sorted list or as simple as a string, into a single programmingentity that includes data and logic. Further, other objects can not invokethe encapsulated data or logic. In order to interact, other objects mustsend messages to an object's interface that will cause the object to performa function that will have a known effect. See also entry under 2.3 Messages.
6. Identity, Equality, Copy
Smalltalk provides unique identity for all objects. Objects can be testedfor equivalence (Are the objects being compared the same object?) and equality(every object may implement its own definition of equality).
Copying of objects can be performed as a deep copy (object's structureand the objects pointed to by its variables are copied) or shallow copy(objects pointed to by variables, their variables are not copied, but areshared with the original object).
7. Types and Classes
Smalltalk does not have a separate notion of "type" (messageprotocol shared by a group of objects) apart from "class."
A class is a group of objects that represent the same type of entityand share the same methods. A class describes the implementation of a setof similar objects. Classes are themselves objects. All objects belongto some class and an object is an instance of the class of which it belongs.
8. Inheritance and Delegation
Smalltalk class relationships are defined in terms of inheritance. Theproperties of one class are be inherited from another class in a hierarchicalstructure beginning with the upper-most class (Object). In inheritance,the inheriting class is called the subclass and the class being inheritedfrom is call the superclass. A subclass inherits all of its superclass'variables and methods.
Abstract classes are classes from which other classes are inherited(subclassed) only. Instances can be implemented any non-abstract class.
Subclasses are specialization of their superclasses. A subclass mayadd variables, but it cannot delete those inherited from the superclass.A subclass may accept an inherited method or it may override the methodby providing an new method with the same name (or message selector).
Object instances are instances of a class. Smalltalk does not providefor delegation (defined as object instances being created from other objectinstances and not a class).
9. Noteworthy Objects
9.1 relationships
The most common relationships in Smalltalk are the inter-class relationshipsdefined by the inheritance class hierarchy. In addition, an object is relatedto another object when it has a pointer to that object. Most implementationsof Smalltalk include support for "dependency" using these instancerelationships. This serves the need to link objects together and coordinatethe behavior between them. An example of this would be for one object toknow when a variable value change occurs in a "dependent" object.
9.2. attributes
Attributes are known as class and instance variables in Smalltalk. ASmalltalk object's instantiated variables are stored in its private memoryand called instance data. Instance variables can be "named" (accessibleby name from the methods within the object instance) or "indexed"(accessed by pointer reference). Smalltalk does not support public attributes.
9.3 literals
There are five types of literals in Smalltalk. Those literal types are:
9.4 containment
Smalltalk furnishes a number of different types of "collection"classes that support containment groupings of objects in various ways thatprovide specific behavior for the given type of collection. The followingcollections are standard in most Smalltalk implementations:
9.5 aggregates
See entry under 9.4 containment.
9.6 other
10. Extensibility
The underlying concepts and structure of the Smalltalk languages areminimalistic and the real capability of the language is delivered by thesignificant number of system and standard classes defined in all Smalltalkimplementations. These classes, and thus "the language," areinfinitely extensible.
10.1 dynamic
Typical implementations of Smalltalk are fully dynamic. See entriesunder 4. Polymorphism, 7. Types and Classes, and 10. Extensibility.
10.2 metaclasses/metaobject protocol
All classes are represented as an instance of a metaclass.
10.3 introspection
Typically Smalltalk implementations offer complete introspection.
11. Object Languages
Smalltalk is a pure object-oriented programming language with its ownself-contained development environment.
12. Semantics of Base Classes (+type constructors)
Smalltalk has a few built-in classes and typical mechanisms for definingnew classes.
13. Background and References
[GR83] Adele Goldberg and D. Robson, Smalltalk-80: The Language andIts Implementation, Addison-Wesley, 1983.
[IBM92] Smalltalk Portability: A Common Base, Document NumberGG24-3903, IBM Corporation, International Technical Support Center, BocaRaton, September 1992.