Object-based vs. Class-based Languages



Similar documents
Comp 411 Principles of Programming Languages Lecture 34 Semantics of OO Languages. Corky Cartwright Swarat Chaudhuri November 30, 20111

Checking Access to Protected Members in the Java Virtual Machine

Concepts and terminology in the Simula Programming Language

Data Abstraction and Hierarchy

Lecture 1: Introduction

History OOP languages Year Language 1967 Simula Smalltalk

Reuse Contracts: Managing the Evolution of Reusable Assets

Object-Oriented Software Specification in Programming Language Design and Implementation

THE IMPACT OF INHERITANCE ON SECURITY IN OBJECT-ORIENTED DATABASE SYSTEMS

Glossary of Object Oriented Terms

INHERITANCE, SUBTYPING, PROTOTYPES in Object-Oriented Languages. Orlin Grigorov McMaster University CAS 706, Fall 2006

The Service Revolution software engineering without programming languages

Object-Oriented Type Inference

Tutorial on Writing Modular Programs in Scala

On the Design of an Object Oriented Programming Language

Research Topics in Software Composition

Compiling Object Oriented Languages. What is an Object-Oriented Programming Language? Implementation: Dynamic Binding

Programming Languages

DYNAMIC, INSTANCE-BASED, OBJECT-ORIENTED PROGRAMMING IN MAX/MSP USING OPEN SOUND CONTROL MESSAGE DELEGATION

Patterns in. Lecture 2 GoF Design Patterns Creational. Sharif University of Technology. Department of Computer Engineering

Organization of Programming Languages CS320/520N. Lecture 05. Razvan C. Bunescu School of Electrical Engineering and Computer Science

On Understanding Types, Data Abstraction, and Polymorphism

Systematically Refactoring Inheritance to Delegation in JAVA

Evolution of the Major Programming Languages

Wyvern: A Simple, Typed, and Pure Object-Oriented Language

Composing Concerns with a Framework Approach

Functional Programming. Functional Programming Languages. Chapter 14. Introduction

Structuring Product-lines: A Layered Architectural Style

Chapter 7 Application Protocol Reference Architecture

Quotes from Object-Oriented Software Construction

Fundamentals of Java Programming

Abstraction in Computer Science & Software Engineering: A Pedagogical Perspective

Optimization of Object-Oriented Programs Using Static Class Hierarchy Analysis

On Understanding Types, Data Abstraction, and Polymorphism

A Comparative Analysis of Structured and Object-Oriented Programming Methods ASAGBA, PRINCE OGHENEKARO; OGHENEOVO, EDWARD E. CPN, MNCS.

Overview. Elements of Programming Languages. Advanced constructs. Motivating inner class example

The Phases of an Object-Oriented Application

Characteristics of Java (Optional) Y. Daniel Liang Supplement for Introduction to Java Programming

æ A collection of interrelated and persistent data èusually referred to as the database èdbèè.

CS-XXX: Graduate Programming Languages. Lecture 25 Multiple Inheritance and Interfaces. Dan Grossman 2012

On the Applicability of Io, a Prototype-Based Programming Language

Chapter 1. Dr. Chris Irwin Davis Phone: (972) Office: ECSS CS-4337 Organization of Programming Languages

Java (12 Weeks) Introduction to Java Programming Language

CS422 - Programming Language Design

Language Evaluation Criteria. Evaluation Criteria: Readability. Evaluation Criteria: Writability. ICOM 4036 Programming Languages

Software Development Processes. Software Life-Cycle Models

The Learning Psychology of Visual Programming for Object-Orientation

Understanding Software Static and Dynamic Aspects

Formal Engineering for Industrial Software Development

Concurrency in Object-Oriented Programming Languages

Verifying Semantic of System Composition for an Aspect-Oriented Approach

Object-Oriented Programming Versus Abstract Data Types

Functional Programming

Software Development Processes. Software Life-Cycle Models. Process Models in Other Fields. CIS 422/522 Spring

Object Oriented Databases. OOAD Fall 2012 Arjun Gopalakrishna Bhavya Udayashankar

Aspect-Oriented Programming

Challenges and Opportunities for formal specifications in Service Oriented Architectures

REST Client Pattern. [Draft] Bhim P. Upadhyaya ABSTRACT

International Journal of Advanced Research in Computer Science and Software Engineering

Module 12. Software Project Monitoring and Control. Version 2 CSE IIT, Kharagpur

22C:22 (CS:2820) Object-Oriented Software Development

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

Web Presentation Layer Architecture

1 Organization of Operating Systems

Unification of AOP and FOP in Model Driven Development

Johannes Sametinger. C. Doppler Laboratory for Software Engineering Johannes Kepler University of Linz A-4040 Linz, Austria

CEC225 COURSE COMPACT

Announcements FORTRAN ALGOL COBOL. Simula & Smalltalk. Programming Languages

CHAPTER 2 MODELLING FOR DISTRIBUTED NETWORK SYSTEMS: THE CLIENT- SERVER MODEL

CSCI 3136 Principles of Programming Languages

Completeness, Versatility, and Practicality in Role Based Administration

Module 2. Software Life Cycle Model. Version 2 CSE IIT, Kharagpur

Object Oriented Design

Object Oriented Database Management System for Decision Support System.

Diamond Effect in Object Oriented Programming Languages

CSE 307: Principles of Programming Languages

Fourth generation techniques (4GT)

Transcription:

Abstract Object-based vs. Class-based Languages Luca Cardelli Digital Equipment Corporation Systems Research Center PLDIÕ96 Tutorial Class-based object-oriented programming languages take object generators as central, while object-based languages emphasize the objects themselves. This dichotomy, or spectrum, has been explicitly recognized for at least 15 years. During this time, class-based languages have become relatively well-understood (or well-misunderstood), widely debated, and hugely popular. In contrast, the area of object-based languages has evolved within a smaller and more varied community, and is still underdeveloped. Much of its visibility is due today to the Self language which, in many ways, is the Smalltalk of object-based programming. But where are the Simula and the C++ of object-based programming? It seems that they have not been invented yet, or certainly they are not as popular. Luca Cardelli, 1996 PLDI 96 Tutorial April 3, 1996 12:2 pm 1 History of this Material Designing a class-based language (Modula-3). Designing an object-based language (Obliq). Learning about other object-based languages. PLDI 96 Tutorial April 3, 1996 12:2 pm 2 CLASS-BASED LANGUAGES The mainstream. We discuss only common, kernel properties. ~ Organizing what I learned. Working on object calculi. ~ Filling the gap between object calculi and object-oriented languages. PLDI 96 Tutorial April 3, 1996 12:2 pm 3 Class-Based Languages April 3, 1996 12:2 pm 4

Classes and Objects Classes are descriptions of objects. Naive Storage Model Object = reference to a record of attributes. Example: storage cells. class cell is var contents: Integer := ; method (): Integer is return self.contents; method (n: Integer) is self.contents := n; object reference contents Naive storage model attribute record (code for ) (code for ) Self. Class-Based Languages April 3, 1996 12:2 pm 5 Class-Based Languages April 3, 1996 12:2 pm 6 Object Creation Objects are created from classes via new. (InstanceTypeOf(c) indicates the type of an object of class c.) var mycell: InstanceTypeOf(cell) := new cell; Object Operations Field selection. Field update. Method invocation. procedure double(acell: InstanceTypeOf(cell)) is acell.(2 * acell.()); Class-Based Languages April 3, 1996 12:2 pm 7 Class-Based Languages April 3, 1996 12:2 pm 8

The Method-Suites Storage Model Embedding vs. Delegation A more refined storage model for class-based languages. Þeld suite contents method suite (code for ) (code for ) In the naive storage model, methods are embedded in objects. contents attribute record (code for ) (code for ) contents 1 Method suites In the methods-suites storage model, methods are delegated to the method suites. Þeld suite contents method suite (code for ) (code for ) contents 1 Class-Based Languages April 3, 1996 12:2 pm 9 Class-Based Languages April 3, 1996 12:2 pm 1 Method Lookup Naive and method-suites models are semantically equivalent for class-based languages. The contrast between embedding and delegation will be our main theme. It will becomes particularly important in the context of object-based languages. Method lookup is the process of finding the code to run on a method invocation o.m(é). The details depend on the language and the storage model. Class-Based Languages April 3, 1996 12:2 pm 11 Class-Based Languages April 3, 1996 12:2 pm 12

The Great Class-Based Illusion In class-based languages, method lookup gives the illusion that methods are embedded in objects (cf. o.x, o.m(...)). Self is always the receiver: the object that appears to contain the method. Features that would distinguish embedding from delegation implementations (e.g. method update) are usually avoided. This illusion hides the details of the storage model and of method lookup. Subclasses and Inheritance A subclass is a differential definition of a class. The subclass relation is the partial order induced by the subclass declarations. Example: restorable cells. subclass recell of cell is var backup: Integer := ; override (n: Integer) is self.backup := self.contents; super.(n); method restore() is self.contents := self.backup; Class-Based Languages April 3, 1996 12:2 pm 13 Class-Based Languages April 3, 1996 12:2 pm 14 Subclasses and Self Because of subclasses, the meaning of self becomes dynamic. Subclasses and Naive Storage In the naive implementation, the existence of subclasses does not cause any change in the storage model. self.m(...) Because of subclasses, the concept of super becomes useful. super.m(...) acell arecell contents contents backup restore attribute record (code for ) (code for ) attribute record (code for ) (code for ) (code for restore) Class-Based Languages April 3, 1996 12:2 pm 15 Class-Based Languages April 3, 1996 12:2 pm 16

Subclasses and Method Suites Because of subclasses, the method-suites model has to be reconsidered. In dynamically-typed class-based languages, it is modified: In statically-typed class-based languages, however, it is maintained in its original form. acell acell contents (code for ) (code for ) arecell contents (code for ) (code for ) arecell (code for ) contents backup restore (new code for ) (code for restore) contents backup restore (new code for ) (code for restore) Collapsed method suites Hierarchical method suites Class-Based Languages April 3, 1996 12:2 pm 17 Class-Based Languages April 3, 1996 12:2 pm 18 Embedding/Delegation View of Class Hierarchies Hierarchical method suites: delegation (of objects to suites) combined with delegation (of sub-suites to supersuites). Collapsed method suites: delegation (of objects to suites) combined with embedding (of super-suites in sub-suites). Class-Based Summary In analyzing the meaning and implementation of classbased languages we end up inventing and analyzing sub-structures of objects and classes. These substructures are independently interesting: they have their own semantics, and can be combined in useful ways. What if these substructures were directly available to programmers? Class-Based Languages April 3, 1996 12:2 pm 19 Class-Based Languages April 3, 1996 12:2 pm 2

OBJECT-BASED LANGUAGES Slow to emerge. Simple and flexible. Usually untyped. Objects without Classes Just objects and dynamic dispatch. When typed, just object types and subtyping. Direct object-to-object inheritance. Object-Based Languages May 28, 1996 11:9 pm 21 Object-Based Languages May 28, 1996 11:9 pm 22 An Object, All by Itself Classes are replaced by object constructors. Object types are immediately useful. ObjectType Cell is var contents: Integer; method (): Integer; method (n: Integer); object cell: Cell is var contents: Integer := ; method (): Integer is return self.contents method (n: Integer) is self.contents := n An Object Generator Procedures as object generators. procedure newcell(m: Integer): Cell is object cell: Cell is var contents: Integer := m; method (): Integer is return self.contents method (n: Integer) is self.contents := n return cell; var cellinstance: Cell := newcell(); Quite similar to classes! Object-Based Languages May 28, 1996 11:9 pm 23 Object-Based Languages May 28, 1996 11:9 pm 24

Decomposing Class-based Features Prototypes and Clones General idea: decompose class-based notions. (And orthogonally recombine them.) We have seen how to decompose simple classes into objects and procedures. Object generation by parameterization. Vs. object generation by cloning and mutation. We will now investigate how to decompose inheritance. Object-Based Languages May 28, 1996 11:9 pm 25 Object-Based Languages May 28, 1996 11:9 pm 26 Prototypes Classes describe objects. Prototypes describe objects and are objects. Cloning of Prototypes Regular objects are clones of prototypes. var cellclone: Cell := clone cellinstance; clone is a bit like new, but operates on objects instead of classes. Object-Based Languages May 28, 1996 11:9 pm 27 Object-Based Languages May 28, 1996 11:9 pm 28

Mutation of Clones Self-Mutation Clones are customized by mutation (e.g., update). Field update. cellclone.contents := 3; Method update. cellclone. := method (): Integer is if self.contents < then return else return self.contents Restorable cells with no backup field. ObjectType ReCell is var contents: Integer; method (): Integer; method (n: Integer); method restore(); Object-Based Languages May 28, 1996 11:9 pm 29 Object-Based Languages May 28, 1996 11:9 pm 3 Forms of Mutation The method updates the restore method! object recell: ReCell is var contents: Integer := ; method (): Integer is return self.contents method (n: Integer) is let x = self.(); self.restore := method () is self.contents := x self.contents := n; method restore() is self.contents := Method update is an example of a mutation operation. It is simple and statically typable. Forms of mutation include: ~ Direct method update (Beta, NewtonScript, Obliq, Kevo, Garnet). ~ Dynamically removing and adding attributes (Self, Act1). ~ Swapping groups of methods (Self, Ellie). Object-Based Languages May 28, 1996 11:9 pm 31 Object-Based Languages May 28, 1996 11:9 pm 32

Object-Based Inheritance Object generation can be written as procedures, but with no real notion of inheritance. Object inheritance can be achieved by cloning (reuse) and update (override), but with no shape change. How can we inherit while changing shape? An Option: Object Extension Object extension achieves inheritance and shape change. However: ~ Not easy to typecheck. ~ Not easy to implement efficiently. ~ Provided rarely or restrictively. Object-Based Languages May 28, 1996 11:9 pm 33 Object-Based Languages May 28, 1996 11:9 pm 34 Donors and Hosts General object-based inheritance: building new objects by ÒreusingÓ attributes of existing objects. Two orthogonal aspects: ~ obtaining the attributes of a donor object, and ~ incorporating those attributes into a new host object. Four categories of object-based inheritance: ~ The attributes of a donor may be obtained implicitly or explicitly. Orthogonally: ~ those attributes may be either embedded into a host, or delegated to a donor. Embedding vs. Delegation Inheritance A difference in execution. Embedding inheritance: the attributes inherited from a donor become part of the host (in principle, at least). Delegation inheritance: the inherited attributes remain part of the donor, and are accessed via an indirection from the host. Either way, self is the receiver. In embedding, host objects are independent of their donors. In delegation, complex webs of dependencies may be created. Object-Based Languages May 28, 1996 11:9 pm 35 Object-Based Languages May 28, 1996 11:9 pm 36

Implicit vs. Explicit Inheritance A difference in declaration. Implicit inheritance: one or more objects are designated as the donors (explicitly!), and their attributes are implicitly inherited. Explicit inheritance, individual attributes of one or more donors are explicitly designated and inherited. Intermediate possibility: explicitly designate a named collection of attributes that, however, does not form a whole object. E.g. mixin inheritance. (We can see implicit and explicit inheritance, as the extreme points of a spectrum.) Super and override make sense for implicit inheritance, not for explicit inheritance. Object-Based Languages May 28, 1996 11:9 pm 37 Object-Based Languages May 28, 1996 11:9 pm 38 Embedding Host objects contain copies of the attributes of donor objects. Embedding and Self Embedding provides the simplest explanation of the standard semantics of self as the receiver. acell contents (code for ) (code for ) The invocation of an inherited method works exactly like the invocation of an original method. arecell contents backup restore (new code for ) (new code for ) (code for restore) Embedding Object-Based Languages May 28, 1996 11:9 pm 39 Object-Based Languages May 28, 1996 11:9 pm 4

Embedding-Based Languages Explicit Embedding Inheritance Embedding was described by Borning as part of one of the first proposals for prototype-based languages. Recently, it has been adopted by languages like Kevo and Obliq. We call these languages embedding-based (concatenation-based, in Kevo terminology). Embedding inheritance can be specified explicitly or implicitly. ~ Explicit forms of embedding inheritance can be understood as reassembling parts of old objects into new objects. ~ Implicit forms of embedding inheritance can be understood as ways of concatenating or extending copies of existing objects with new attributes. Individual methods and fields of specific objects (donors) are copied into new objects (hosts). We write embed o.m(é) to embed the method m of object o into the current object. The meaning of embed cell.(n) is to execute the method of cell with self bound to the current self, and not with self bound to cell as in a normal invocation cell.(n). Moreover, the code of is embedded in recellexp. Object-Based Languages May 28, 1996 11:9 pm 41 Object-Based Languages May 28, 1996 11:9 pm 42 recellexp object cell: Cell is var contents: Integer := ; method (): Integer is return self.contents method (n: Integer) is self.contents := n object recellexp: ReCell is var contents: Integer := cell.contents; var backup: Integer := ; method (): Integer is return embed cell.(); method (n: Integer) is self.backup := self.contents; embed cell.(n); method restore() is self.contents := self.backup The code for could be abbreviated to: method copied from cell; Object-Based Languages May 28, 1996 11:9 pm 43 Object-Based Languages May 28, 1996 11:9 pm 44

Implicit Embedding Inheritance recellimp Whole objects (donors) are copied to form new objects (hosts). We write object o: T extends oõ to designate a donor object oõ for o. As a consequence of this declaration, o is an object containing a copy of the attributes of oõ, with independent state. object cell: Cell is var contents: Integer := ; method (): Integer is return self.contents method (n: Integer) is self.contents := n object recellimp: ReCell extends cell is var backup: Integer := ; override (n: Integer) is self.backup := self.contents; embed super.(n); method restore() is self.contents := self.backup Object-Based Languages May 28, 1996 11:9 pm 45 Object-Based Languages May 28, 1996 11:9 pm 46 Alternate recellimp via method update We could define an equivalent object by a pure extension of cell followed by a method update. object recellimp1: ReCell extends cell is var backup: Integer := ; method restore() is self.contents := self.backup recellimp1. := method (n: Integer) is self.backup := self.contents; self.contents := n; This code works because, with embedding, method update affects only the object to which it is applied. (This is not true for delegation.) Stand-alone recell The definitions of both recellimp and recellexp can be seen as convenient abbreviations: object recell: ReCell is var contents: Integer := ; var backup: Integer := ; method (): Integer is return self.contents method (n: Integer) is self.backup := self.contents; self.contents := n; method restore() is self.contents := self.backup Object-Based Languages May 28, 1996 11:9 pm 47 Object-Based Languages May 28, 1996 11:9 pm 48

Delegation Host objects contain links to the attributes of donor objects. Prototype-based languages that permit the sharing of attributes across objects are called delegation-based. Operationally, delegation is the redirection of field access and method invocation from an object or prototype to another, in such a way that an object can be seen as an extension of another. Delegation and Self A crucial aspect of delegation inheritance is the interaction of donor links with the binding of self. On an invocation of a method called m, the code for m may be found only in the donor cell. But the occurrences of self within the code of m refer to the original receiver, not to the donor. Therefore, delegation is not redirected invocation. Note: similar to hierarchical method suites. Object-Based Languages May 28, 1996 11:9 pm 49 Object-Based Languages May 28, 1996 11:9 pm 5 Explicit Delegation Inheritance Individual methods and fields of specific objects (donors) are linked into new objects (hosts).. acell contents We write (code for ) (code for ) delegate o.m(é) to execute the m method of o with self bound to the current self (not to o). arecell contents backup Ð donor links The difference between delegate and embed is that the former obtains the method from the donor at the time of method invocation, while the latter obtains it earlier, at the time of object creation. restore (new code for ) (code for restore) (An example of) Delegation Object-Based Languages May 28, 1996 11:9 pm 51 Object-Based Languages May 28, 1996 11:9 pm 52

recellexp object recellexp: ReCell is var contents: Integer := cell.contents; var backup: Integer := ; method (): Integer is return delegate cell.() method (n: Integer) is self.backup := self.contents; delegate cell.(n); method restore() is self.contents := self.backup Explicit delegation provides a clean way of delegating operations to multiple objects. It provides a clean semantics for multiple donors. Object-Based Languages May 28, 1996 11:9 pm 53 Object-Based Languages May 28, 1996 11:9 pm 54 Implicit Delegation Inheritance (Traditional Delegation) Whole objects (donors/parents) are shared to from new objects (hosts/children). We write acell contents (code for ) (code for ) object o: T child of oõ parent link to designate a parent object oõ for o. As a consequence of this declaration, o is an object containing a single parent link to oõ, with parent state shared among children. Parent links are followed in the search for attributes. arecell contents backup restore (new code for ) (code for restore) (Single-parent) Delegation Object-Based Languages May 28, 1996 11:9 pm 55 Object-Based Languages May 28, 1996 11:9 pm 56

recellimp A first attempt. object cell: Cell is var contents: Integer := ; method (): Integer is return self.contents method (n: Integer) is self.contents := n object recellimpõ: ReCell child of cell is var backup: Integer := ; override (n: Integer) is self.backup := self.contents; delegate super.(n); method restore() is self.contents := self.backup This is almost identical to the code of recellimp for embedding. But for delegation, this definition is wrong: the contents field is shared by all the children. Object-Based Languages May 28, 1996 11:9 pm 57 Object-Based Languages May 28, 1996 11:9 pm 58 A proper definition must include a local copy of the contents field, overriding the contents field of the parent. object recellimp: ReCell child of cell is override contents: Integer := cell.contents; var backup: Integer := ; override (n: Integer) is self.backup := self.contents; delegate super.(n); method restore() is self.contents := self.backup On an invocation of recellimp.(), the method is found only in the parent cell, but the occurrences of self within the code of refer to the original receiver, recellimp, and not to the parent, cell. Hence the result of () is, as desired, the integer stored in the contents field of recellimp, not the one in the parent cell. Object-Based Languages May 28, 1996 11:9 pm 59 Object-Based Languages May 28, 1996 11:9 pm 6

Dynamic Inheritance Inheritance is called static when inherited attributes are fixed for all time. It is dynamic when the collection of inherited attributes can be updated dynamically (replaced, increased, decreased). Mode Switching Although dynamic inheritance is in general a dangerous feature, it enables rather elegant and disciplined programming techniques. In particular, mode-switching is the special case of dynamic inheritance where a collection of (inherited) attributes is swapped with a similar collection of attributes. (This is even typable.) Object-Based Languages May 28, 1996 11:9 pm 61 Object-Based Languages May 28, 1996 11:9 pm 62 Delegation-Style Mode Switching Embedding-Style Mode Switching ßip a of attributes acell arecell old parent contents 1 (code for ) (code for ) ßip a parent link new parent contents 2 (other code for ) (other code for ) restore old object contents backup (code for ) (code for ) (code for restore) restore new object contents backup (other code for ) (other code for ) (code for restore) contents backup Method Update restore (new code for ) (code for restore) Reparenting Object-Based Languages May 28, 1996 11:9 pm 63 Object-Based Languages May 28, 1996 11:9 pm 64

Embedding vs. Delegation Summary In embedding inheritance, a freshly created host object contains copies of donor attributes. Access to the inherited donor attributes is no different than access to original attributes, and is quick. Storage use may be comparatively large, unless optimizations are used. In delegation inheritance, a host object contains links to external donor objects. During method invocation, the attribute-lookup procedure must preserve the binding of self to the original receiver, even while following the donor links. ~ This results in more complicated implementation and formal modeling of method lookup. ~ It creates couplings between objects that may not be desirable in certain (e.g. distributed) situations. Object-Based Languages May 28, 1996 11:9 pm 65 Object-Based Languages May 28, 1996 11:9 pm 66 In class-based languages the embedding and delegation models are normally (mostly) equivalent. In object-based languages they are distinguishable. ~ In delegation, donors may contain fields, which may be updated; the changes are seen by the inheriting hosts. ~ Similarly, the methods of a donor may be updated, and again the changes are seen by the inheriting hosts. ~ It is often permitted to replace a donor link with another one in an object; then all the inheritors of that object may change behavior. ~ Cloning is still taken to perform shallow copies of objects, without copying the corresponding donors. Thus, all clones of an object come to share its donors and therefore the mutable fields and methods of the donors. Object-Based Languages May 28, 1996 11:9 pm 67 Object-Based Languages May 28, 1996 11:9 pm 68

Advantages of Delegation Thus, embedding and delegation are two fundamentally distinct ways of achieving inheritance with prototypes. Interesting languages exist that explore both possibilities. Space efficiency by sharing. Convenience in performing dynamic, pervasive changes to all inheritors of an object. Well suited for integrated languages/environments. Object-Based Languages May 28, 1996 11:9 pm 69 Advantages of Embedding Delegation can be criticized because it creates dynamic webs of dependencies that lead to fragile systems. Embedding is not affected by this problem since objects remain autonomous. In embedding-based languages such as Kevo and Omega, pervasive changes are achieved even without donor hierarchies. Object-Based Languages May 28, 1996 11:9 pm 7 Traits: from Prototypes back to Classes? Prototypes were initially intended to replace classes. Several prototype-based languages, however, seem to be moving towards a more traditional approach based on class-like structures. Prototypes-based languages like Omega, Self, and Cecil have evolved usage-based distinctions between objects. Space efficiency, while essential, is best achieved behind the scenes of the implementation. ~ Even delegation-based languages optimize cloning operations by transparently sharing structures; the same techniques can be used to optimize space in embedding-based languages. Object-Based Languages May 28, 1996 11:9 pm 71 Object-Based Languages May 28, 1996 11:9 pm 72

Different Kinds of Objects Not all These Object are ÒTrueÓ Objects Trait objects. Prototype objects. Normal objects. prototype acell contents object trait (code for ) (code for ) In the spirit of classless languages, traits and prototypes are still ordinary objects. However, there is a separation of roles. Traits are intended only as the shared parents of normal objects: they should not be used directly or cloned. Prototypes are intended only as object (and prototype) generators via cloning: they should not be used directly or modified. clone(acell) contents Traits Object-Based Languages May 28, 1996 11:9 pm 73 Object-Based Languages May 28, 1996 11:9 pm 74 Trait Treason Normal objects are intended only to be used and to carry local state: they should rely on traits for their methods. These distinctions may be seen as purely methodological, or may be enforced: for example, some operations on traits and prototypes may be forbidden to protect these objects from accidental damage. This separation of roles violates the original spirit of prototype-based languages. Traits objects cannot function on their own. With the separation between traits and other objects, we seem to have come full circle back to class-based languages and to the separation between classes and instances. Object-Based Languages May 28, 1996 11:9 pm 75 Object-Based Languages May 28, 1996 11:9 pm 76

Object Constructions vs. Class Implementations The Contribution of the Object-Based Approach The traits-prototypes partition in delegation-based languages looks exactly like an implementation technique for classes. A similar traits-prototypes partition in embeddingbased languages corresponds to a different implementation technique for classes that trades space for access speed. Class-based notions and techniques are not totally banned in object-based languages. Rather, they resurface naturally. The achievement of object-based languages is to make clear that classes are just one of the possible ways of generating objects with common properties. Objects are more primitive than classes, and they should be understood and explained before classes. Different class-like constructions can be used for different purposes. Hopefully, more flexibly than in strict class-based languages. Object-Based Languages May 28, 1996 11:9 pm 77 CONCLUSIONS Class-based: various implementation techniques based on embedding and/or delegation. Self is the receiver. Object-based: various language mechanisms based on embedding and/or delegation. Self is the receiver. Object-Based Languages May 28, 1996 11:9 pm 78 Foundations Objects can emulate classes (by traits) and procedures (by Òstack frame objectsó). Everything can indeed be an object. Object-based can emulate class-based. (By traits, or by otherwise reproducing the implementations techniques of class-based languages.) PLDI 96 Tutorial May 28, 1996 11:9 pm 79 PLDI 96 Tutorial May 28, 1996 11:9 pm 8

Future Directions I look forward to the continued development of typed object-based languages. ~ The notion of object type arise more naturally in object-based languages. ~ Traits, method update, and mode switching are typable (general reparenting is not easily typable). Embedding-based languages seem to be a natural fit for distributed-objects situations. E.g. COM vs. CORBA. ~ Objects are self-contained and are therefore localized. ~ For this reason, Obliq was designed as an embedding-based language. No need for dichotomy: object-based and class-based features can be merged within a single language, based on the common object-based semantics (Beta, OÐ1, OÐ2, OÐ3). PLDI 96 Tutorial May 28, 1996 11:9 pm 81 PLDI 96 Tutorial May 28, 1996 11:9 pm 82 A New Hierarchy BIBLIOGRAPHY Object-Oriented Class-Based Object-Based Closures Prototypes Embedding Delegation Implicit... Explicit Implicit... Explicit [1] Abadi, M. and L. Cardelli, A theory of objects. Springer. 1996 (to appear). [2] Abadi, M. and L. Cardelli, A theory of primitive objects: untyped and first-order systems. Proc. Theoretical Aspects of Computer Software. Lecture Notes in Computer Science 789, 296-32. Springer-Verlag. 1994. [3] Adams, N. and J. Rees, Object-oriented programming in Scheme. Proc. 1988 ACM Conference on Lisp and Functional Programming, 277-288. 1988. [4] Agesen, O., L. Bak, C. Chambers, B.-W. Chang, U. Hšlzle, J. Maloney, R.B. Smith, D. Ungar, and M. Wolczko, The Self 3. programmer's reference manual. Sun Microsystems. 1993. [5] Alagic, S., R. Sunderraman, and R. Bagai, Declarative object-oriented programming: inheritance, subtyping, and prototyping. Proc. ECOOP'94. Lecture Notes in Computer Science 821, 236-259. Springer-Verlag. 1994. [6] Andersen, B., Ellie: a general, fine-grained, first-class, object-based language. Journal of Object Oriented Programming 5(2), 35-42. 1992. [7] Apple, The NewtonScript programming language. Apple Computer, Inc. 1993. [8] Blaschek, G., Type-safe OOP with prototypes: the concepts of Omega. Structured Programming 12(12), 1-9. 1991. PLDI 96 Tutorial May 28, 1996 11:9 pm 83 PLDI 96 Tutorial May 28, 1996 11:9 pm 84

[9] Blaschek, G., Object-oriented programming with prototypes. Springer-Verlag. 1994. [1] Borning, A.H., The programming language aspects of ThingLab, a constraintoriented simulation laboratory. ACM Transactions on Programming Languages and Systems 3(4), 353-387. 1981. [11] Borning, A.H., Classes versus prototypes in object-oriented languages. Proc. ACM/IEEE Fall Joint Computer Conference, 36-4. 1986. [12] Cardelli, L., A language with distributed scope. Computing Systems, 8(1), 27-59. MIT Press. 1995. [13] Chambers, C., The Cecil language specification and rationale. Technical Report 93-3-5. University of Washington, Dept. of Computer Science and Engineering. 1993. [14] Chambers, C., D. Ungar, and E. Lee, An efficient implementation of Self, a dynamically-typed object-oriented language based on prototypes. Proc. OOPS- LA'89, 49-7. ACM Sigplan Notices 24(1). 1989. [15] Dony, C., J. Malenfant, and P. Cointe, Prototype-based languages: from a new taxonomy to constructive proposals and their validation. Proc. OOPSLA'92, 21-217. 1992. [16] Lieberman, H., A preview of Act1. AI Memo No 625. MIT. 1981. [17] Lieberman, H., Using prototypical objects to implement shared behavior in object oriented systems. Proc. OOPSLA'86, 214-223. ACM Press. 1986. [18] Lieberman, H., Concurrent object-oriented programming in Act 1. In Objectoriented concurrent programming, A. Yonezawa and M. Tokoro, ed., MIT Press. 9-36. 1987. [19] Madsen, O.L., B. M ller-pedersen, and K. Nygaard, Object-oriented programming in the Beta programming language. Addison-Wesley. 1993. [2] Paepcke, A., ed., Object-oriented programming: the CLOS perspective. MIT Press, 1993. [21] Rajendra, K.R., E. Tempero, H.M. Levy, A.P. Black, N.C. Hutchinson, and E. Jul, Emerald: a general-purpose programming language. Software Practice and Experience 21(1), 91-118. 1991. [22] Stein, L.A., H. Lieberman, and D. Ungar, A shared view of sharing: the treaty of Orlando. In Object-oriented concepts, applications, and databases, W. Kim and F. Lochowsky, ed., Addison-Wesley. 31-48. 1988. [23] Taivalsaari, A., Kevo, a prototype-based object-oriented language based on concatenation and module operations. Report LACIR 92-2. University of Victoria. 1992. [24] Taivalsaari, A., A critical view of inheritance and reusability in object-oriented programming. JyvŠskylŠ Studies in computer science, economics and statistics No.23, A. Salminen, ed., University of JyvŠskylŠ. 1993. [25] Taivalsaari, A., Object-oriented programming with modes. Journal of Object Oriented Programming 6(3), 25-32. 1993. PLDI 96 Tutorial May 28, 1996 11:9 pm 85 PLDI 96 Tutorial May 28, 1996 11:9 pm 86 [26] Ungar, D., C. Chambers, B.-W. Chang, and U. Hšlzle, Organizing programs without classes. Lisp and Symbolic Computation 4(3), 223-242. 1991. [27] Ungar, D. and R.B. Smith, Self: the power of simplicity. Lisp and Symbolic Computation 4(3), 187-25. 1991. PLDI 96 Tutorial May 28, 1996 11:9 pm 87