<<

Dimensions of Object-Based Language Design

Peter Wegner Department of Brown University Providence RI 02912

Abstract: These features span the design space of object-based The design space of object-based languages is languages. Each relates to a different aspect of com- characterized in terms of objects, classes, inheritance, putational behavior. Objects are autonomous enti- data abstraction, strong typing, concurrency, and ties that respond to messages or operations and share persistence. Language classes (paradigms) associated a state. Classes classify objects by their common with interesting subsets of these features are operations. Inheritance serves to classify classes by identified and language design issues for selected their shared behavior. Data abstraction hides the paradigms are examined. Orthogonal dimensions representation of data and the implementation of that span the object-oriented design space are related operations. Strong typing imposes static constraints to non-orthogonal features of real languages. The on the appiicability of operations, both within and self-referential application of object-oriented metho- among objects. Concurrency allows objects to exe- dology to the development of object-based language cute concurrently with other objects and to have paradigms is demonstrated. internal concurrency. Persistence allows object iden- tity to persist across applications and to be indepen- Delegation is defined as a generalization of dent of values or keys used in object selection. inheritance and design alternatives such as non-strict, multiple, and abstract inheritance are considered. Language classes worthy of special study are Actors and prototypes are presented as examples of identified and the efficiency, simplicity, and methodol- classless (delegation based) languages. Processes are ogy of the associated paradigms is examined. We classified by their degree of internal concurrency. first consider just objects, classes, and inheritance, The potential inconsistency of object-oriented sharing then add data abstraction and strong typing, and and distributed autonomy is discussed, suggesting finally consider concurrency and persistence. Along that compromises between sharing and autonomy will the way global properties of design dimensions such be necessary in designing strongly typed object- as consistency and orthogonality are introduced and oriented distributed languages. related to non-orthogonal features that occur in real languages. 1. Design Space for Object-Based Languages 2. Objects, Classes, and Inheritance In order to examine design alternatives for object-based languages the following “dimensions” of Objects have the following properties: language design are considered: object: An object has a set of “operations” and a that remembers the effect of operations. objects “state” classes Objects may be contrasted with functions, which have no memory. Function values are completely inheritance determined by their arguments, being precisely the data abstraction same for each invocation. In contrast, the value strong typing returned by an operation on an object may depend concurrency on its state as well as its arguments. An object may persistence learn from experience, its reaction to an operation Permission to copy without fee all or part of this material is granted provided being determined by its invocation history. that the copies are not made or distributed for direct commerical 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 The term “object-based language” may now be Machinery. To copy otherwise, or to republish, requires a fee and/ defined as follows: or specific permission. ici 1987 ACM O-8979 l-247-0/87/00 10-0168 $1.50

168 OOPSLA ‘87 Proceedings October 4-8,1987 object-based language: A language is object-based The class of object-oriented languages is nar- if it supports objects as a language feature. rower than the class of object-based languages, excluding languages like Ada, Modula, and CLU but including languages like Smalltalk and C++. Support of objects is a necessary but not sufficient requirement for being object-oriented. Ada is object-based but is not object-oriented Object-oriented languages must additionally support according to our definition because its objects (pack- object classes and class inheritance: ages) do not have a class (type). CLU’s clusters are effectively classes since they serve as templates for object-oriented language: An object-based creating instances and allow instances to be “first- language is object-oriented if its objects belong to class objects” in the sense that they can be assigned classes and class hierarchies may be incrementally to variables, be passed as parameters, and be com- defined by an inheritance mechanism. That is: ponents of structures. But CLU does not have an inheritance relation for defining hierarchical relations object-oriented = objects + classes + inheritance between clusters, and is therefore not object-oriented. In accordance with our approach of naming The notions “class” and “inheritance” used in “interesting*’ language classes we call object-based the above definition can be defined as follows: languages which require every object to have a class “class-based” or “classical” languages. class: A class is a template (cookie cutter) from which objects may be created by “create” or “new” class-based (classical) languages: An object-based operations. Objects of the same class have common language is class-based (classical) if every object has operations and therefore uniform behavior. Classes a class. have one or more “interfaces” that specify the opera- tions accessible to clients through that . A Class-based languages are a proper subset of “class body” specifies code for implementing opera- object-based languages, while object-oriented tions in the class interface. languages are in turn a proper subset of class-based languages. Ada is an example of an object-based inheritance: A class may inherit operations from language that is not class-based while CLU is an “superclasses” and may have its operations inherited example of a class-based language that is not object- by “subclasses”. An object of the class C created by oriented. This hierarchy of language classes is illus- the operation “C new” has C as its “base class” and trated in Figure 1. may use operations defined in its base class as well as operations defined in superclasses. Inheritance from a single superclass is called single inheritance; inheri- tance from multiple superclasses is called multiple t classes inheritance. i @&y&.;;;;:, Ada, Actors Inheritance is here defined narrowly as a mechanism for resource sharing in class hierarchies. In the literature the term is used loosely to denote a variety of other forms of hierarchical resource shar- i Simula,Smalltalk ing. We will later define “delegation” as a more gen- eral class-independent term for dynamic hierarchical resource sharing. Figure 1: From Object-Based to Object- The class of object-based languages includes Oriented Languages Ada [DOD], Modula [Wi], CLU [LSAS], and Actor languages [Ag] but not Pascal, Algol, or Fortran. Figure 1 may be viewed as an inheritance Ada’s objects are realized by packages, Modula’s hierarchy which uses object-oriented techniques to objects are called modules, and CLU’s objects are classify object-based languages. We may think of instances of clusters. class-based languages as inheriting the attributes of object-based languages, and of object-oriented languages as in turn inheriting the attributes of both

0&&r 4-a, i 987 OOPSLA‘87 Proceedings 189 the class-based and the object-based languages. This strong typing: A language is strongly typed if type self-application of object-oriented methodology to compatibility of all expressions representing values object-based languages both illustrates its general can be determined from the static program represen- power in classifying and organizing knowledge and tation at compile time. provides substantive insight into the particular domain which is the subject of this paper. Object-oriented languages with data abstrac- It is not surprising that object-oriented inheri- tion and strong typing are a narrower class of tance surfaces as a technique for defining the relation languages with stronger structuring properties than between language classes. Figure 1 classifies the class we have chosen to call object-oriented. This languages into hierarchies by imposing progressively narrower class excludes Simula, whose objects are not stronger requirements on the features they possess. data abstractions because their instance variables Such classification is precisely the purpose of inheri- can be accessed by other objects, and Smalltalk, tance in object-oriented systems, as pointed out in which is not strongly typed because its variables may [we]. be assigned values of different type at different points We briefly consider the impact of objects, of execution. The term “object-oriented” has been classes, and inheritance on programming methodol- carefully defined to be sufficiently narrow to exclude ogy. Objects serve to group operations with the data languages like Ada, Modula, and CLU and sufficiently they will transform and provide a data-oriented prin- broad to include languages like Simula and ciple for program design. Classes serve to manage Smalltalk. collections of objects, allowing objects to be treated Object-oriented languages which have strong as first-class values within the language so that they typing and require all objects to be data abstractions can be passed as parameters, assigned as values of will be called strongly typed object-oriented variables, and organized into structures. Class inher- languages: itance serves to organize collections of classes, allow- ing application domains to be described by class strongly typed object-oriented language: An hierarchies. object-oriented language is strongly typed if it has Object-based languages like Ada support the strong typing and requires all objects to be data functionality of objects. But object management abstractions. must be handled by mechanisms outside the language like libraries, because it is not supported within the Strong typing and data abstraction have the language. Class-based languages languages provide common objective of strengthening object modularity some degree of management of objects within the but are independent in the sense that strong typing is language but no mechanism for the management of possible for objects that are not data abstractions (as classes. Object-oriented languages allow both objects demonstrated by Simula), and data abstraction is and classes to be managed within the language, possible without strong typing and indeed without thereby providing a uniform mechanism for both any typing at all (as demonstrated by Smalltalk). design and implementation of applications. They are Should object-oriented languages require “wide spectrum languages” because they support both abstraction and strong typing? Smalltalk has cons- the high-level design of class hierarchies and the low- ciously avoided strong typing in order to achieve level implementation of objects. dynamic binding, while Lisp-based object-oriented languages in the Flavors tradition [Mo,DG] have 3. Data Abstraction and Strong Typing consciously avoided both strong typing and abstrac- The terms “data abstraction” and “strong typ- tion. Flavors goes even further and does not actually ing”, may be defined as follows: have objects as a language primitive. It has the more primitive notion of a data template to which opera- data abstraction: A data abstraction is an object tions may be attached. Flavors do not specify opera- whose state is accessible only through its operations. tions but may be used as an anchor for operations. The state is generally represented by instance vari- Thus Flavors-style languages are not, strictly speak- ables. Instance variables of a data abstraction are ing, object-based but serve as a substrate which may hidden from its clients and are accessible only be used in an object-based or object-oriented way. through the object’s operations.

170 OOPSIA ‘87 Proceedings October 4-8, 1987 The inclusion of data abstraction and strong be demonstrated by exhibiting a language that has typing is clearly not an unqualified benefit. It the set of features. involves a tradeoff between structure and discipline on the one hand and flexibility and efficiency on the The five features that define strongly typed other. Abstraction is good when we can commit our- object-oriented languages are consistent since selves to particular abstractions early in the design strongly typed languages exist, for example Owl [SC]. process, but may be unduly constraining when we are Moreover, consistency of a set of features implies con- unsure of the precise abstractions appropriate to a sistency of any subset of the features. problem and wish to experiment with abstractions as part of the design and prototyping process. This is A collection of language features is orthogonal often the case with artificial intelligence applications if no feature is a consequence of any of the other or in other experimental applications concerned with language features. This notion of independence is understanding concepts that underlie a class of prob- captured by the following condition: lems rather than with the solution of a specific prob- lem. Lisp-based object-oriented systems are intended orthogonality: A collection of features is orthogonal for such applications and consciously provide non- (independent) if, for every subset, there is a language abstract objects to enhance the conceptual flexibility that possesses that subset of features and no features of problem solving. in the complementary subset. Does it make sense to have non-abstract strongly typed languages? Although languages like Objects, classes, and inheritance are far from Simula illustrate that commitment to strong typing is orthogonal. Classes are defined in terms of objects possible without commitment to abstraction, this and inheritance is in turn defined in terms of classes. may be a historical accident. It may well be that We write this dependence as follows: non-abstract objects are useful primarily for untyped formalisms where the absence of both abstractions classes + objects and types encourages conceptual flexibility. Typed inheritance + classes formalisms may discourage experimentation to such an extent that non-abstract objects are no longer This lack of orthogonality suggests that we look useful. However, this is just speculation, and closer for orthogonal concepts that define the essence of analysis might well reveal that non abstract strongly being a class in an object-independent way and the typed objects are in fact useful in certain kinds of essence of inheritance in a way that is independent of experimental applications. classes and objects. In the case of classes the orthog- In spite of these reservations, the accepted wis- onal concept is the notion of type which, as a first dom is that strongly typed object-oriented languages approximation, may be defined as follows: should be the norm for application programming and especially for programming in the large. An object- type: A type is a behavior specification that may be oriented programming environment should probably used to generate instances having the behavior. support Lisp-style untyped programming for purposes of prototyping and strongly typed object-oriented The orthogonality of objects and types is illus- languages for traditional application programming. trated by Ada which has a well developed notion of Moreover, there should be provision for automatically type and even strong typing but does not support freezing experimental prototype code to turn it into typed objects. strongly typed code if and when it is ready to be used In order to define a notion of inheritance for production programming. orthogonal to classes and objects the clasa- independent “essence” of inheritance must be 4. Consistency and Orthogonality identified. We view inheritance as a mechanism for The consistency of a collection of language sharing incrementally defined resources that internal- features may be defined as follows: izes shared resources, treating them as part of an extended self. Following Cook [Co], we define a consistency: A collection of language features is con- class-independent form of inheritance in terms of a sistent if they can coexist, that is, if there is a “model particular mechanism for self-reference that allows language” that realizes the features. Consistency can remotely defined operations to be internalized as part

Odober 4-8,1987 OOPSLA‘87 Proceedings of the extended identity of an object. The class- entity by an interface that controls access to the independent notion of inheritance will be called dele- entity by other entities. gation and may be defined as follows: Strong typing is not orthogonal since it is a delegation: Delegation is a mechanism that, allows form of typing. There is no additional dimension objects to delegate responsibility for performing an because strong typing simply requires every value to operation or finding a value to one or more desig- have a type and that operator/operand compatibility nated “ancestors”. A key feature is that self- can be determined at compile time. Thus strongly reference in an ancestor dynamically denotes the typed object-oriented languages can be characterized delegating object, thereby allowing the ancestor to be in a design space with the following four orthogonal part of the extended identity of the delegating object. dimensions: Dynamic binding of self-reference realizes sharing and reusability by allowing the resources of an ancestor objects - modular computing agents to be part of the extended identity of different types - expression classification mechanism delegating objects at different points of execution. delegation - resource sharing mechanism abstraction - interface specification mechanism Delegation is defined independently of classes. The key concept is the internalization of delegated These dimensions provide a design framework operations so they can be treated as part of an for object-based languages in terms of computing extended self. Delegation is defined to be a form of agents, classification mechanisms, sharing mechan- resource sharing that allows shared resources to be isms, and interface specification mechanisms. Specific viewed as belonging to the entity on behalf of which languages in this design space are defined by con- they are executed. This effect is realized by dynami- straints on these design dimensions such as the spe- cally binding “self’ to each entity on behalf of which cialization of types to have classes and include strong it is executed for the duration of its execution. Thus typing, of delegation to be inheritance of classes, and a given operation can “belong” to different entities on of abstraction to be data abstraction. The con- different instances of execution. straints define a subspace of the design space deter- Inheritance may be viewed as a specialization mined by orthogonal design dimensions. of delegation in which the entities that inherit are classes, and is therefore considered to be in the same 5. Design Alternatives for Delegation “design dimension” as delegation. If we had to choose Delegation may be specialized by selecting between these two notions to characterize this design among the following design alternatives: dimension we would choose delegation, since it is purer and is “orthogonal” to other design dimensions. However, inheritance is more familiar and is needed (1) classless delegation versus inheritance to characterize object-oriented programming Classless delegation realizes dynamic sharing in an instance hierarchy while while inheritance Methodologically, orthogonality is a nice pro- realizes dynamic sharing in a class hierarchy. perty of design dimensions that is useful for purposes (2) striEt versus non-strict inheritance of classification. When dimensions are not, orthogonal Strict inheritance requires descendants to be it is often useful to go through the exercise of identi- fying what it takes to make them orthogonal, as we behaviorally compatible with ancestors, while non-strict inheritance allows operations of did in identifying the notion of delegation as an ancestors to be arbitrarily redefined and cap orthogonal form of the notion of inheritance. tures the notion of “similarity” rather than How can we extend the design space determined “behavioral compatibility. In between there are by objects, types, and delegation to take account of forms of controlled redefinition. In [WZ] we data abstraction and strong typing? Data abstrac- refer to strict behavioral compatibility as an tion is not orthogonal to these dimensions because it “is-a” relation and to non-strict similarity as a depends on objects. The associated orthogonal notion “like” relation. is abstraction or -defined so that it single versus multiple inheritance is uniformly applicable to any entity: (3) Multiple inheritance allows an object to inherit from multiple ancestors and provides a abstraction: An abstraction is a specification of an

October 4-8,1987 172 OOPSLA ‘87 Proceedings more flexible behavior composition mechanism Pugh [LTP], Hailpern and Nguyen [HN], and others than single inheritance. There is no agreement in exploring classless models of inheritance. on the mechanisms of method combination that Our definition of delegation differs from that of multiple inheritance should support. Lieberman [Li] in that we view inheritance as a spe- (4 abstract interface versus code sharing cial case of delegation while Lieberman views delega- Should sharing by inheritance be at the level tion and inheritance as two distinct mechanisms. We of code sharing or abstract interfaces? have taken the liberty of slightly redefining the term Smalltalk and Flavors view inheritance as a to focus on the class-independent essence of inheri- code sharing mechanism. CommonObjects [Sn] tance rather than on a concept that parallels inheri- is based on abstract inheritance. Actra [LTP] tance. We could have used another term but the supports both specification hierarchies based on term “delegation” seems to capture the intuition of abstract inheritance and implementation sharing by delegating responsibility without commit- hierarchies based on code sharing. ment to either classes or class-independence. Delegation captures the essence of the dynamic Figure 2 demonstrates the hierarchical selection resource-sharing paradigm underlying inheritance in of design alternatives. It shows that the object- a purer form than the earlier class-dependent oriented classification method can be applied to pro- definition. Features of dynamic hierarchical resource gressively more finely grained design decisions to sharing are more clearly characterized by delegation select among’alternative delegation strategies. than in terms of specialized notions of inheritance. We consider two such features, namely object auton- omy and virtual operations. The dynamic resource sharing provided by dele- gation has its costs in object autonomy. It is as though objects are connected to ancestors by an umbilical cord which they can never cut. Such dynamic sharing is expensive in distributed systems where ancestors are in different distributed com- ponents from their descendants. Delegation is an acceptable sharing mechanism for objects in a single address space but may be unacceptable as a sharing mechanism between address spaces. The notion of virtual operations of Simula and other class-based languages may be defined more gen- erally for delegation-based languages. Virtual opera- tions arise when an ancestor specifies resources that will be implemented later in a descendant:

virtual resource (operation): A resource (opera- Figure 2. Design Alternatives for Inheritance tion) named and specified in an ancestor whose imple- mentation will be provided by a descendant. 6. Delegation-Based Languages Since classless object-based languages with dele- In class-based languages classes with virtual gation are interesting we christen them as follows: resources are called abstract classes and cannot be instantiated because there is generally no way to delegation-based languages: A delegation-based bind virtual to actual resources except at instance language is an object-based language that supports creation time. classless objects and delegation: delegation-based = objects - classes + delegation abstract class: A class with virtual resources that can be instantiated only as an instance of a subclass for which virtual resources of the cl&s are imple- Delegation was conceived by Lieberman [Li] and mented. used by Cook [Co], Stein /St], Lalonde, Thomas, and

Odobr 4-8,1987 OOPSIA ‘87 Proceedings 173 However, there is no inherent reason why (3) auxiliary entities separately defined actual resources should not be con- Classes are auxiliary entities having no neces- nected to already created objects either at load time sary existence in the domain of discourse being or dynamically as they are generated by the system. modelled. The class hierarchy (Integer, Specification and implementation should be Number, Magnitude, Object) used to model sufficiently decoupled so that implementations can be integers in Smalltalk is determined by an arbi- bound to specifications in a flexible way. trary design decision of Smalltalk rather than by a necessary property of the integers. We 7. Classless Languages may in principle dispense with auxiliary Objects not required to have a class will be abstractions and capture the properties of col- called classless objects and languages with classless lections of objects directly by prototypes whose objects will be called classless languages: properties serve to specify both particular instances and defaults for dependent instances. classless objects: Objects that do not have a class. classless languages: Object-based languages whose Languages with classless objects are object- objects may be classless. based but not object-oriented. We can subdivide such languages into two categories: Classless languages represent a more radical form of typelessness than languages that are object- classless languages without delegation oriented but not strongly typed. The relation classless languages with delegation between Smalltalk and classless languages is similar to that between Snob014 and Lisp. Values in Snob014 We shall examine Actor languages as an exam- have a type but allow variables to assume values of ple of classless languages without delegation, and different types at different points of execution, while Lieberman’s prototypes [Li] as an example of classless values in Lisp are untyped. Classlessness provides languages with delegation. greater freedom for experimental programming than lack of strong typing but is correspondingly less 8. Actors structured. The arguments in favor of classlessness Actor languages support objects, abstraction, include the following: and concurrency but not classes, inheritance, or strong typing: (1) class-independent operations It does not always make sense to associate an actor languages = operation with a specific class, since: objects + abstraction + concurrency a) an operation may have objects of several - classes - inheritance - strong typing different classes as arguments, and transform the state of several different classes. Actor languages are low-level languages that b) an operation may transform not only an .may be used to build higher-level, more structured object’s state but also its interface. languages. The concurrency supported by actors is c) an operation may be applicable to many fine-grained in the sense that actors not only execute different classes (friends in C++) concurrently with other actors but may also execute (2) classes with a singleton element their internal actions concurrently. Actors represent When classes have just a single instance (the a point in the design space of object-based languages class of all planets nearest the sun or of all suc- very different from that of traditional object-oriented cessors of 0) the separate specification of shared languages. They raise fundamental questions relating behavior and a non-shared state makes no to the nature of concurrency that are beyond the sense, since the shared behavior is shared by scope of this paper. We are here interested in actor only one object. However, when such classes languages because of the clear and simple model they are formed by specialization (inheritance) from provide of objects without classes rather than as a more general classes (the class of planets or basis for a practical . integers) then classes with even a singleton ele- Actors are objects which have a mail address ment may be worthwhile. (mailbox name) and a behavior. The mail address

174 OOPSIA ‘87 Proceedings October 4-8,1987 designates a buffer which can store an unbounded communications that contain the mailbox name. linear sequence of messages (called “communica- (3) It must designate a successor with the same tions”). The behavior of an actor is defined by its identity (mailbox name) as its parent to process actions in response to a communication. A pure the next communication to the actor. The actor can process just a single communication from behavior of the successor is called the replace- its mailbox before it “dies”. Computational actors, ment behavior. There are no constraints on the like the human ones described in Macbeth, “strut and relation between the behavior of an actor and fret their hour upon the stage and then are no more”. its replacement behavior. In particular, the The identity of an actor is determined by its message set meaningful for an actor mailbox name which is firmly decoupled from its state (corresponding to its set of operations) need and behavior. Moreover, the state and behavior for bear no relation to the message set meaningful an actor is totally independent of the state and for its successor. behavior of its successor. The process of creating a successor is not unlike reincarnation in that the Supposing an actor sends p communications to “soul”, represented by the mailbox name, is reincar- other actors and creates q new actors as well as its nated for an entirely new body. successor before it dies. These p+q+l activities are An actor may respond to a communication by in principle concurrent, so that the processing of a sending messages, creating new actors, and creating single communication spawns p+q+l concurrent its replacement, as illustrated in Figure 3: tasks. The successor actor occupies a special place among these since it represents the continuation of the main process. Th e successor may initiate its activity by responding to the next communication in the mailbox as soon as it is fully created, and may execute concurrently while its progenitor is complet- ing its other tasks. This permits pipelining, that is, concurrently applying the sequence of incarnations of a given actor to a sequence of communications in its mailbox. specifies replacement The actor associated with a mail queue has a sequence of incarnations with Xn representing the incarnation that processes the nth communication. Xn must wait until its communication (in slot n of the mailbox) arrives. It then creates a replacement behavior X(n+l) which processes the (n+l)th com- munication, and may send communications to other actors and create new actors with associated new mail queues. Following (Ag] we briefly show how the factorial function is computed in the actor formalism. We define a factbrial actor which responds to messages of the form (n,r), where n is the integer whose factorial is being computed and r is the mailbox to which the Figure 3: Behavior of Actors result will be sent. The factorial actor has a simple response when n=O and a more complex response when n>O. (1) An actor may send a finite number of communi- cations to other actors with known mailbox When n=O the factorial actor simply sends a names (its acquaintances). message with value 1 to the actor with mailbox address r. When n>O it performs the following (2) It may create a finite number of new actors. actions: The mailbox name of newly created names is known to the creating actor and may be disseminated to other actors by sending them

October 4-8,1987 OOPSLA‘87 Proceedings 175 (1) It creates a replacement behavior Fn that has responsibility for performing operations or finding the same behavior as the original factorial values to a prototype. The prototype provides actor. defaults for its operations and values to objects that (2) It creates an actor, say “An”, which computes request the prototype to perform an operation on “n*k” on receiving the message k arid sends the their behalf. result to r. (3) It sends a message to “self” consisting of the When classes that have only a single member integer “n-l” and the return address of the we are assured that there will never be an occasion newly created actor “An”. If (n-l) > 0 this in when the prototype needs to be used as a template, turn causes its replacement behavior to and it can play the role of an instance without wor- 1) create an actor “A(n-1)” which, on receiving rying about the effect of changes on delegating the message k, computes “(n-l)*k”, and objects. Even when classes have many members pro- 2) send the message with integer (n-2) and totypes are a natural way of representing the first return address “A(n-1)” to self. member of the class that is encountered but may cause problems when additional members delegate their default behavior to the prototype. Thus the message “(n,r)” sent to the factorial actor will create a sequence of n incarnations of the For example, if we encounter an elephant, say factorial actor Fn, F(n-1), ..,, Fl, and an associated Clyde, there is no need to store both the instance and set of created actors An, A(n-1), . . . . Al such that Ai its class and we may store just the instance. If we will receive a message with value (i-l) factorial and then encounter a second elephant, say Fred, we can send i factorial to A(i+l). Finally, “An” will receive view Clyde as a prototype for representing knowledge (n-l) factorial and send n factorial to r. about Fred. Fred may be represented by his differences from Clyde. Properties that Fred shares This example does not demonstrate concurrency with Clyde can be omitted from the representation of since the computation takes 2*n sequential steps: n to Fred since the default values in Fred’s prototype create the auxiliary actors An,...,Al, and another n Clyde may be used. to perform the n multiplications. Using actors to compute factorials is like using a sledgehammer to In this example, prototypes require less over- crack a nut. But it does illustrate the role of replace- head than the alternative of creating an elephant ment behavior, actor creation, and message creation abstraction independent of Clyde and Fred. They in a concrete, albeit simple, computation. In doing so also appear to model the cognitive acquisition of it provides insight into the reasons for requiring these knowledge about elephants more naturally. It is only three mechanisms as a basis for defining actor compu- after seeing many elephants that an elephant tation. abstraction becomes cognitively established and prac- tically useful. The prototype mechanism appears to Actors provide a flexible model of computation model knowledge acquisition more closely than the based on a powerful computation primitive. The class mechanism for human cognitive processes, and model is too powerful and flexible for most computa- its computational models have less overhead for tions that arise in practice, and certainly too power- classes with a small number of instances. However, ful for computing factorials. However, the actor classes model cognitive processes and knowledge model simply demonstrates how computations on organization of the specialist so that both mechan- classless objects may be realized and how the model isms are needed to span the complete range of cogni- may be specialized to class preserving computations, tive situations. namely by constraining the replacement behavior. We shall refer to delegation-based languages based on prototypes as “prototypical”: 9. Prototypes

Delegation-based languages allow objects to prototypical languages: Prototypical languages are share and internalize operations of “ancestor” objects, delegation-based languages that realize delegation by called prototypes, that serve both as instances and as prototypes. templates for descendants: The transition from a prototypicai to a classical prototype: A prototype is an object that is both an representation of objects could in principle be instance and a template. Objects may delegate

October 4-8,1987 176 OOPSLA ‘87 Proceedings performed automatically. It reflects the leap in distinguish between two sharing mechanisms: sharing abstraction that comes from recognizing the common of class attributes by instances and sharing of super- structure of a collection of instances and defining a class attributes by classes. In contrast, prototypical class that captures this structure. It is performed languages have just one kind of sharing, namely the repeatedly in childhood in learning the meanings of sharing by instances (which may be prototypes) of words like cookie, dog, and table. In computation, default properties defined in their prototypes. unification is an example of an automatic method of Delegation may be used for managing shared finding the common structure of a collection of pat- information represented by prototypes. However, our terns. A similar technique could be developed for definition of delegation is broader than Lieberman’s finding the common class structure of a collection of and may be used also for managing shared informa- objects. Moreover, the commonality assumptions tion in classical inheritance. could be expressed as constraints on variability and the “unification” technique could be reapplied when- 10. Object-Based Concurrency ever variability constraints were violated. Concurrent object-based languages model the The distinction between classical and prototypi- world by concurrently executable objects called cal systems reflects a long-standing philosophical processes. The term “process” is used in the context debate concerning the status and representation of of operating systems to mean a machine language abstraction. Plato viewed abstractions like “ideal” representation of a computation that is performed on tables as having an existence more real than a processor . We use the term in the context of pro- instances of tables in the real world. Object-oriented gramming languages to capture the higher-level languages like Smalltalk are Platonic in their explicit notion of a concurrently executing object: use of classes to represent similarity among collec- tions of objects. process: Processes have an interface of executable The alternative view, that abstractions are operations or entry points and one or more threads of unnecessary auxiliary constructs, has not been pro- control that may be active or suspended. pounded as cogently, probably because, taken to the extreme, it may simply be wrong. While any given Process-based languages are object-based set of auxiliary entities may be unnecessary in the languages whose objects may execute concurrently. description of a domain of discourse, the stronger position that complex domains should be described process-baskd language: A process-based language without any auxiliary entities whatsoever seems is an object-based language that has processes. untenable.

Prototypical systems are adequate as a primi- Object-based languages model the world by tive substrate for organizing domains of discourse, autonomous objects that are constrained to execute just as untyped computational formalisms such as sequentially. Process-based languages extend the assembly languages or the lambda calculus are ade- autonomy of objects to autonomy in time. quate for expressing all possible computations. How- ever, when a prototypical system or untyped formal- The primitive executable processing elements ism is used to model a complex universe, types and within a process are called threads: classes for expressing regularities in the domain creep in by the back door, and it becomes preferable to thread: A thread consists of a thread control block introduce explicit typing and classification schemes containing a locus of control and a stack which rather than rely on ad hoc ingenuity. It may well be represents its “state” of execution and is initially appropriate to adopt a prototyping view of the world empty. in the early stages of modelling a domain and to switch to a typed view when the classes appropriate Threads are data structures that can become to the domain become established. In switching from active by being loaded into a processor. Thread data an untyped to a typed model we give up some flexibil- structures may be passed as message requests to ity in the interests of structure and regularity. processes, and may be queued in message buffers until Classical and prototypical languages have a process is ready to execute them. They may be different approaches to the knowledge representation suspended if conditions required for their execution of shared abstractions. Classical languages are not appropriate and reactivated when the

Ckbber ha,1987 OOPSIA ‘87 Proceedings 177 conditions again obtain. We classify processes in Note that all three language classes are fully terms of the properties of their threads. concurrent. They differ in their restriction on con- We distinguish between sequential processes currency within processes but are similar in placing with a single thread of control, quasi-concurrent no restriction on concurrency between processes. processes with at most one active thread of control, Restrictions on concurrency between processes and concurrent processes with multiple threads of are in fact useful in defining weaker (subconcurrent) control. languages that allow multiple independent but not concurrent threads. For example, Simula with its sequential process: A process that has just one coroutines and Smalltalk 80 with its “processes” are thread of control. “quasi-concurrent languages” because they allow quasi-concurrent process: A process that has at objects to have independent threads of control but most one active thread of control. allow only one thread to execute at a time: concurrent process: A process that may have multiple active threads of control. sequential language: A languages with a single thread of control. Sequential processes (Ada and Nil) generally quasi-concurrent language: A language with mul- have a body with an interface of entry points at tiple independent threads but only one active thread. which messages to perform operations may be queued. concurrent language: A language with multiple An invoking operation (incoming message) must wait active threads. until the already executing process is ready to accept it by means of a “rendezvous” which joins the incom- In this section we are committed to full con- ing and active threads of control for purposes of syn- currency at the language level and focus on design chronization and argument communication and then alternatives for concurrency within processes. The separates the threads so that invoking and invoked question whether processes should have internal con- processes may again proceed in parallel. currency can be addressed at the level of both con- Quasi concurrent processes allow threads of ceptual modelling and language design. At the con- control to be suspended while waiting for a condition ceptual level some applications are more naturally to be fulfilled and resumed when the condition is modelled by sequential or quasi-concurrent processes satisfied. They differ from sequential processes in while others are more naturally modelled by fully having “condition queues” of suspended threads as concurrent processes. well as entry queues of threads that are waiting to At the design and implementation levels sequen- enter the process. An incoming thread can become tial and quasi-concurrent processes allow the unit of active only if the current thread terminates or is modularity and concurrency to be the same and suspended, or if the incoming thread fuses with the result in much simpler languages than concurrent active thread by a mechanism such as rendezvous. processes. Concurrent processes permit units of Monitors [Ho, Ha] are an example of quasi-concurrent modularity to contain multiple units of concurrency processes. and require distinct synchronization and communica- In concurrent processes there is no restriction on tion mechanisms for inter and intra process con- active threads and an invoking operation may freely currency at both the language and system levels create a new thread. But attempts to access shared ww - data in critical regions (atomic objects in Argus) may However, concurrent processes are more uniform cause a thread to be suspended until the shared data in permitting the same concurrency primitives to be can safely be accessed. Concurrency within processes used both within and between processes. They have allows finer-grained control that permits suspension a hierarchical rather than a flat process structure. to be delayed from process entry time to the time of Moreover, concurrent processes permit more finely entry to critical regions. grained concurrency and are more expressive in modelling situations in the real world which require The concurrent languages CSP [HOI], Ada, and such concurrency. Nil [SY] have sequential processes. Monitor-based languages like DP [Ha], ABCL/l [YEE], and Orient The step from sequential to quasi-concurrent 84/K [IT] have quasi-concurrent processes. Actor processes makes scheduling of threads within a pro- languages and Argus [Li] have concurrent processes. cess more flexible without causing mutual exclusion

October4-8,1987 178 OOPSLA‘87 Proceedings problems for simple access to data structures. How- This is particularly true when concurrency is aug- ever, quasi-concurrent processes present mutual exclu- mented by the stronger requirement that processes be sion problems when processing transactions because distributed: suspending a thread in the middle of a transaction could cause integrity constraints of the transaction to distributed process: A distributed process is a pro- be violated. cess with a separate address space, that is, it cannot Transactions may be viewed as “temporal directly access any resources outside its local address modules” in the sense that they represent uninterrup- space and can communicate with the outside world tible non-atomic temporal units of execution. Quasi only by . concurrent processes present no mutual exclusion problems for atomic operations but cause problems Distribution increases the autonomy of when we try to combine the temporal modularity of processes but makes it expensive to share nonlocal transactions with the traditional spatial modularity resources by mechanisms such as inheritance or dele- of objects and processes. Concurrent languages based gation. In fact, we can say that distribution is incon- on quasi-concurrent processes, like ABCL/l or Orient sistent with inheritance. This explains why there are 84K, are harder to extend to transaction processing no languages with distributed processes that support than languages based on concurrent sequential inheritance. processes. Thus there is a tradeoff between flexibility The inconsistency between distribution and and extensibility in replacing sequential by quasi- inheritance arises because the goals of modularity concurrent processes. and sharing are incompatible, Modularity requires Concurrent object-oriented systems must be strong separation between components of a system able to handle transactions and must therefore deal while sharing requires fusion of components. with temporal modularity (atomic actions) as well as Dynamic sharing requires fusion of components during spatial modularity (atomic objects). Mechanisms for execution and is incompatible with distribution which transaction-based concurrency control have been requires execution time separation. reviewed in [BG]. The carefully crafted concurrency Design alternatives for distributed processes control mechanisms of the Argus system are decribed involve interaction between the units of modularity, in [LS]. A model for nested transactions in terms of concurrency, and name space. input/output automata is presented in [LM]. unit of modularity: 11. Distributed Processes Unit that defines the user interface Is concurrency consistent with and orthogonal unit of concurrency: to the design dimensions of sequential object-based Unit that represents a single thread programming? This question has a simpler answer for unit of naming: Unit that determines name space orthogonality than for consistency, Concurrency in its general form is clearly orthogonal to other design Processes for which the unit of modularity, con- dimensions. However, in the context of object-based currency, and naming are the same are called distri- programming we are concerned with concurrently buted sequential processes. executing objects. Processes specialize the notion of concurrency in the direction of object-based distributed sequential processes: A distributed languages. They implement the notion of con- sequential process is a distributed process with its currency in a particular way and determine a value own name space. or range of values in the dimension of concurrency. Thus concurrency is an orthogonal dimension of language design and processes are a specialization of Distributed sequential processes are aestheti- that dimension. cally appealing because the interface for message passing, mutual exclusion, and transactions can be Concurrency is a consistent extension of sequen- identified. They are a basis for the process model of tial object-based programming, since actors provide NIL [Str]. But this clean identification of interface, an existence proof of concurrent object-based pro- concurrency, and name space comes at a cost of con- gramming. However, there is a potential conflict ceptual flexibility and efficiency. Conceptual flexibil- between the independence required for concurrency ity is sacrificed because the unit of sharing must have and the structured sharing required for inheritance.

October4-8, 1987 OOPSLA‘87 Proceedings Ii9 the same granularity as the unit of modularity and more flexible way of organizing data than relations in concurrency so that sharing among modules or con- a relational database. The class declarations of current units is precluded. Efficiency is sacrificed object-oriented languages can serve as a data because of the high cost of making the transition definition language for . However, an between distributed components. object-oriented language by itself is insufficient to Two distributed processes A, B may share a realize an object-oriented database. third process C if ports of A and B are both con- A database may be viewed as a long-lived nected to a port of C. Such sharing is at the level of object or process with special properties. It is glo- abstract interfaces. Inheritance of abstract inter- bally accessible (sharable) by a large number of users. faces [Sn] is in principle possible for distributed Generally access is asynchronous from the point of processes, although it is a good deal more expensive view of the user, and we may think of the database than in shared memory. as a non terminating process that services asynchro- An important dichotomy in distributed systems nous user requests. Asynchronous access may be han- is that between static and dynamic interconnection: dled either directly by the database process or by a database server that organizes user requests and statically interconnected distributed processes: feeds them to the database. The database itself may The connections of each process to its environment is be a sequential process (dealing with requests in a determined at process creation time and cannot be serial order), a quasi concurrent process, or a fully changed during the subsequent lifetime of the process. concurrent process with locks that enforce mutual exclusion for data access. dynamically interconnected distributed processes: The connections of a process to its Some of the special features of database environment can be changed by language commands processes are enumerated below: during process execution. (1) To support persistence we need a strong notion Ports in dynamically interconnected distributed of object identity that is independent of the key processes are variables to which process connections used in object selection and persists across pro- (sometimes called channels) can be assigned. It is grams and projects. prudent to associate types with ports and to permit (2) We need a query language that can process connection only if the type and input/output mode of traditional database queries (such as finding the port values are compatible with that of the port vari- set of all employees that make more than their able to which it is assigned. Input ports may be managers). This kind of query may involve thought of as sockets and output ports as plugs that objects of more than one type and and produces must fit the sockets. Dynamically interconnected dis- results that are collection of objects. Queries in tributed processes may be modelled by a plugboard relational database languages may be viewed as with wires corresponding to channels of communica- “select” operations on an aggregate type, tion. namely the type “set” or “relation”. They have the form: 12. Object-Oriented Persistence select(set, predicate) Query complexity and efficiency are determined Persistence is a property of data that deter- of the predicate. Relational mines how long it should be kept. In traditional by the nature query languages specify all queries in terms of a languages the lifetime of data generally does not restricted set of relational query primitives transcend the lifetime of a particular program. Some whose optimization has been extensively stu- data, such as locally declared data or procedure died. Object-oriented query languages must parameters, have an even shorter lifetime. Databases accommodate the greater richness of object- store data whose persistence transcends that of indi- oriented specifications for which optimization is vidual programs. Adding persistence to an object- not as well understood. One of the issues in oriented language allows it to be used as a basis for object-oriented query languages is to make database implementation. them efficient, so that the user does not pay in Objects provide a better starting point for terms of efficiency for the flexibility provided by databases than procedures since their state persists object-oriented programming. between the execution of operations. They provide a

180 OOPSLA ‘87 Proceedings Cider 4-8,1987 (3) Since object-oriented databases are particularly meaningful comparisons can be made. suited to the management of evolutionary sys- There are many dependence relations and tems they require a mechanism for version con- design alternatives we have not considered, and our trol and other tools for evolving systems. examples only scratch the surface. But they do (4) Databases should be able to specify constraints demonstrate the potential of exploring dependence and check that constraints are not violated as among design dimensions of a language design space, the database is modified. This may be achieved and- iIlustrate that the use of object-oriented by active variables of triggers [ZW]. classification techniques to structure the design space (5) Multiple views should be supported with simplify the presentation of design alternatives and automatic updating of all views when the data help us to better understand the complex issues is modified. Lazy updating for views that are involved. not currently active is clearly appropriate. Acknowledgements: Discussions with Tom Doeppner and Stan Zdonik helped to clarify the ideas Databases must support transaction processing in the sections on concurrency and persistence. This and concurrency control so that user requests can be research was supported in part by the National Sci- processed in a safe but efficient manner. The level of ence Foundation, IBM Research, ONR contract safety and resilience in the face of and N00014-83-K146, and DARPA order No 4786. hardware failures must be much greater than for traditional programs. Facilities for aborting transac- 14. References tions and for failure recovery must be provided. Type dependent concurrency control [Wei] could con- [Ag] Agha G., Actors, A Model of Concurrent Compu- siderably increase the efficiency of object-based data- tation in Distributed Systems, MIT Press, 1986. base transactions over corresponding relational tran- sactions. [BG] Bernstein B. A. and Goodman N., Concurrency Control in Distributed Database Systems, Computing 13. Conclusions Surveys, June 1981. Persistence is orthogonal to concurrency and to other dimensions for object-oriented language design. [Co] Cook William, Self-Referential Models of Inheri- We therefore have identified a total of six orthogonal tance, Brown University Report, March 1987. dimensions of object-oriented language design: [DG] DeMichel L. G. and Gabriel R. P., The Common objects Lisp Object System, Proc ECOOP 1987. types delegation [Do] Doeppner T. W., Threads - A System for the abstraction Support of Concurrent Programming, Brown Univer- concurrency sity Computer Science Tech Report CS-87-11, June persistence 1987.

R ef erence Manual, US Dept of Defense, This list of dimensions is not in itself surprising [DOD] Ad> and could easily have been generated on the fly. Our July 1980. contribution has been to relate these dimensions to and Robson D., Smalltalk 80: The non orthogonal concepts in real programming [GR] Goldberg A. languages, to examine design tradeoffs and interrela- Language and Its Implementation, Addison-Wesley tions between instances, and to identify and interest- 1983. ing points in the object-oriented design space. [Ha] Hansen P. B., Distributed Processes, A Con- The study of languages as points in a design current Programming Concept, CACM 1978. space and of language classes as classes of an object- oriented hierarchy is a novel approach to the analysis [HN] Hailpern B. and Nguyen V., A Generalized of programming languages. We have tried to demon- Object Model, In Research Directions in Object- strate that this approach is worthwhile when there Oriented Programming, Eds. Shriver and Wegner, are sufficient points in the design space that MIT Press, 1987.

oc4ober 48.1987 OOPSIA '87 Proceedings 181 [Ho] Hoare C. A. R., Monitors, An Operating System Ada from a Process Model Perspective, International Structuring Concept, CACM, October 1974. Ada Conference, Paris, May 1985.

[Hoi] Hoare C. A. R., Communicating Sequential [We] Wegner P., The Object-Oriented Classification Processes, CACM, August 1978. Paradigm, in Research Directions in Object-Oriented Programming, Eds Shriver and Wegner, MIT Press [IT] Ishikawa Y. and Tokoro M., Orient 84K: An 1987. Object-Oriented Concurrent Programming Language for Knowledge Representation, In Object-Oriented [wei] Weihl W. E., Specification and Implementation Concurrent Programming, Eds Yonezawa and of Atomic Data Types, PhD Thesis, MIT March 1984. Tokoro, MIT Press 1987. [Wi] Wirth N., Programming in Modula 2, Springer [Li] Lieberman H., Using Prototypical Objects to Verlag 1982. Implement Shared Behavior in Object-Oriented Languages, OOPSLA 86. [WZ] Wegner P. and Zdonik S., Why Like Isn’t Like Is-a, Brown University Technical Report, April 1984. [LM] Lynch N. and Merritt M., Introduction to the Theory of Nested Transactions, MIT/LCS/TR-367, ryBS] Yonezawa A., Briot J. and Shibayama E., July 1986. Tokyo Institute of Technology, OOPSLA 1986.

[LS] Liskov B. and Scheifler R., Guardians and [ZW] Zdonik S., and Wegner P., Language and Actions, Linguistic Support for Robust Distributed Methodology for Object-Oriented Databases, Hawaii Programs, TOPLAS, July 1983. Conference on System Sciences, Jan 1986.

[LSAS] Liskov B., Snyder A., Atkinson R., and Schaffert C., Abstraction Mechanisms in CLU, CACM, August 1977.

[LTP] Lalonde W. R., Thomas D. A., and Pugh J. R., An Exemplar-Based Smalltalk, OOPSLA 86.

oon D Object-Oriented Programming with Kit , OOPSLA 86.

[SC] Schaffert C. et al., An Introduction to Trellis/Owl, OOPSLA 86.

[Sn] Snyder A., Encapsulation and Inheritance in Object-Oriented Languages, OOPSLA 86.

[St] Stein Lynn, Delegation is Inheritance, OOPSLA 87.

[Str] Strom R., A Comparison of the Object-Oriented and Process Paradigms, SIGPLAN Notices, October 1986.

[SY] Strom R. and Yemini S., NIL: An Integrated Language and System for Distributed Programming, Proc SIGPLAN ‘83 Symposium on Language Issues in Software Systems, June 1983.

[SYW] Strom R., Yemini S., and Wegner P., Viewing

182 OOPSLA ‘87 Proceedings October 4-8,1987