Object-oriented programming is a programming paradigm that uses "Object_" and their interactions to design applications and computer programs.... in which classes are not present, and behavior reuse (known as inheritance in class-based languages) is performed via a process of cloning
Cloning (programming)
In computer science, cloning refers to the making of an exact copy of an object , frequently under the programming paradigm of instance-based programming, or object-oriented programming.... existing objects that serve as prototype
Prototype
A prototype is an original type, form, or instance of something serving as a typical example, basis, or standard for other things of the same category.... s. This model can also be known as class-less, prototype-oriented or instance-based programming.
The original (and most canonical) example of a prototype-based language is the programming language Self developed by David Ungar
David Ungar
David Ungar, an United States computer scientist, co-created the Self programming language with Randall Smith. The SELF development environment's animated user experience was described in the influential paper co-written with Bay-Wei Chang, which won a lasting impact award at the ACM Symposium on User Interface Software and Technology 2004.... and Randall Smith
Randall Smith
Randall Smith is an electroacoustic music composer born March 8, 1960 in Windsor, Ontario, Ontario, Canada, and currently living in Toronto.... .
Discussion
Ask a question about 'Prototype-based programming'
Start a new discussion about 'Prototype-based programming'
Object-oriented programming is a programming paradigm that uses "Object_" and their interactions to design applications and computer programs.... in which classes are not present, and behavior reuse (known as inheritance in class-based languages) is performed via a process of cloning
Cloning (programming)
In computer science, cloning refers to the making of an exact copy of an object , frequently under the programming paradigm of instance-based programming, or object-oriented programming.... existing objects that serve as prototype
Prototype
A prototype is an original type, form, or instance of something serving as a typical example, basis, or standard for other things of the same category.... s. This model can also be known as class-less, prototype-oriented or instance-based programming.
The original (and most canonical) example of a prototype-based language is the programming language Self developed by David Ungar
David Ungar
David Ungar, an United States computer scientist, co-created the Self programming language with Randall Smith. The SELF development environment's animated user experience was described in the influential paper co-written with Bay-Wei Chang, which won a lasting impact award at the ACM Symposium on User Interface Software and Technology 2004.... and Randall Smith
Randall Smith
Randall Smith is an electroacoustic music composer born March 8, 1960 in Windsor, Ontario, Ontario, Canada, and currently living in Toronto.... . However, the classless programming style has recently grown increasingly popular, and has been adopted for the programming language
Programming language
A programming language is a machine-readable artificial language designed to express computations that can be performed by a machine, particularly a computer.... s JavaScript
JavaScript
JavaScript is a scripting language widely used for client-side web development. It was the originating Programming language dialect of the ECMAScript standard.... , Cecil, NewtonScript
NewtonScript
NewtonScript is a prototype based programming language created to write programs for the Newton platform. It is heavily influenced by the Self computer language, but modified to be more suited to needs of mobile and embedded devices.... , Io
Io (programming language)
Io is a pure Object-oriented programming Computer programming Programming language inspired by Smalltalk, Self , Lua , Lisp , Act1, and NewtonScript.... , MOO, REBOL
REBOL
REBOL, the Relative Expression Based Object Language , is a data exchange language and programming languageREBOL Technologies, .... , Lisaac
Lisaac
Lisaac is the first compiled object-oriented programming language based on prototype-based programming concepts, with system programming facilities and design by contract.... and several others.
In its simplest embodiment, an object is an allocated region of storage. Since programming languages use variable#Computer_programmings to access objects, the terms object and variable are often used interchangeably.... come in two general types. Classes
Class (computer science)
In object-oriented programming, a class is a programming language construct that is used as a blueprint to create Object s. This blueprint includes Attribute s and Method s that the created objects all share.... define the basic layout and functionality of objects, and instances are "usable" objects based on the patterns of a particular class. In this model, classes act as collections of behavior (methods
Method (computer science)
In object-oriented programming, a method is a subroutine that is exclusively associated either with a class or with an object . Like a procedure in procedural programming languages, a method usually consists of a sequence of statement to perform an action, a set of input parameter to customize those actions, and possibly an output value... ) and structure that are the same for all instances, whereas instances carry the objects' data. The role distinction is thus primarily based on a distinction between structure and behavior on the one hand, and state
State (computer science)
In computer science and automata theory, a state is a unique configuration of information in a program or machine. It is a concept that occasionally extends into some forms of systems programming such as Lexical analysiss and parsers.... on the other.
Advocates of prototype-based programming often argue that class-based languages encourage a model of development that focuses first on the taxonomy and relationships between classes. In contrast, prototype-based programming is seen as encouraging the programmer to focus on the behavior of some set of examples and only later worry about classifying these objects into archetypal objects that are later used in a fashion similar to classes. As such, many prototype-based systems encourage the alteration of prototypes during runtime
Runtime
In computer science, runtime or run time describes the operation of a computer program, the duration of its execution, from beginning to termination .... , whereas only very few class-based object-oriented systems (such as the first dynamic object-oriented system, Smalltalk
Smalltalk
Smalltalk is an Object-oriented programming, Type system, reflection computer programming programming language. Smalltalk was created as the language to underpin the "new world" of computing exemplified by "human?computer symbiosis." It was designed and created in part for educational use, more so for constructionist learning, at PARC by Al... ) allow classes to be altered during the execution of a program.
While the vast majority of prototype-based systems are based around interpreted and dynamically typed programming languages, it is important to point out that statically typed systems based around prototypes are technically feasible. The Omega programming language discussed in Prototype-Based Programming is an example of such a system, though according to Omega's website even Omega is not exclusively static but rather its "compiler may choose to use static binding where this is possible and may improve the efficiency of a program."
Object construction
In class-based languages a new instance is constructed through the class's constructor
Constructor (computer science)
In object-oriented programming, a constructor in a class is a special block of statements called when an object lifetime#Creating objects, either when it is declared or dynamically constructed on the heap-based memory allocation through the keyword ?new?.... and an optional set of constructor arguments
Parameter (computer science)
In computer programming, a parameter is a special kind of variable#In_computer_programming that refers to data that a subroutine receives to operate on.... . The resulting instance is modeled on the layout and behavior dictated by the chosen class.
In prototype-based systems there are two methods of constructing new objects, through cloning of an existing object, and through ex nihilo
Ex nihilo
The Latin phrase ex nihilo means "out of nothing". It often appears in conjunction with the concept of creation, as in creatio ex nihilo, meaning "creation out of nothing".... ("from nothing") object creation. While most systems support a variety of cloning, ex nihilo object creation is not as prominent.
Systems that support ex nihilo object creation allow new objects to be created from scratch without cloning from an existing prototype. Such systems provide a special syntax for specifying the properties and behaviors of new objects without referencing existing objects. In many prototype languages, there is often a basic Object prototype that carries commonly needed methods and is used as a master prototype for all other objects. One useful aspect of ex nihilo object creation is to ensure that a new object's slot names do not have namespace
Namespace (computer science)
A namespace is an abstract container or environment created to hold a logical grouping of unique identifiers or symbols . An identifier defined in a namespace is associated with that namespace.... collisions with the top-level Object object. (In the Mozilla JavaScript
JavaScript
JavaScript is a scripting language widely used for client-side web development. It was the originating Programming language dialect of the ECMAScript standard.... implementation, one can accomplish this by setting a newly constructed object's __proto__ property to null.)
Cloning refers to a process whereby a new object is constructed by copying the behavior of an existing object (its prototype). The new object then carries all the qualities of the original. From this point on, the new object can be modified. In some systems the resulting child object maintains an explicit link (via delegation
Delegation (programming)
In object-oriented programming there are two related notions of delegation.* Most commonly, it refers to a programming language feature making use of the method lookup rules for dispatching so-called self-calls as defined by Lieberman in his 1986 paper "Using Prototypical Objects to Implement Shared Behavior in Object-Oriented Systems".... or resemblance) to its prototype, and changes in the prototype cause corresponding changes to be apparent in its clone. Other systems, such as the Forth-like programming language Kevo, do not propagate change from the prototype in this fashion, and instead follow a more concatenative model where changes in cloned objects do not automatically propagate across descendants.
//Example of true prototypal inheritance style in javascript.
//"ex nihilo" object creation employing the literal object notation .
var foo = ;
//another "ex nihilo" object.
var bar = ;
//Gecko and Webkit can directly manipulate the hidden __proto__ link.
//IE, Opera et al may need to use the object, clone or Object.beget functions
//to make a new object and set its __proto__ to the parent object and return
//the newly created child object.
bar.__proto__ = foo; // bar is now the child of foo.
//If we try to access foo's properties from bar from now on, we'll succeed.
alert(bar.one); //alerts 1.
//The child objects properties are also accessible.
alert(bar.three); //alerts 3.
Delegation
In prototype-based languages that use delegation, the language runtime is capable of dispatching
Dynamic dispatch
In computer science, dynamic dispatch is the process of mapping a Message passing to a specific sequence of code at runtime. This is done to support the cases where the appropriate method cannot be determined at compile-time .... the correct method or finding the right piece of data simply by following a series of delegation pointers (from object to its prototype) until a match is found. All that is required to establish this behavior-sharing between objects is the delegation pointer. Unlike the relationship between class and instance in class-based object-oriented languages, the relationship between the prototype and its offshoots does not require that the child object have a memory or structural similarity to the prototype beyond this link. As such, the child object can continue to be modified and amended over time without rearranging the structure of its associated prototype as in class-based systems. It is also important to note that not only data but also methods can be added or changed. For this reason, most prototype-based languages refer to both data and methods as "slots".
Concatenation
Under pure prototyping, which is also referred to as concatenative prototypes, and is exemplified in the Kevo language, there are no visible pointers or links to the original prototype from which an object is cloned. The prototype object is copied exactly, but given a different name (or reference). Behavior and attributes are simply duplicated as-is.
Advantages to this approach include the fact that object authors can alter the copy without worrying about side-effects across other children of the parent. A further advantage is that the computational cost of method lookup during dispatch is drastically reduced when compared to delegation, where an exhaustive search must be made of the entire delegation chain before failure to find a method or slot can be admitted.
Disadvantages to the concatenative approach include the organizational difficulty of propagating changes through the system; if a change occurs in a prototype, it is not immediately or automatically available on its clones. However, Kevo does provide additional primitives for publishing changes across sets of objects based on their similarity (so-called family resemblances) rather than through taxonomic origin, as is typical in the delegation model.
Another disadvantage is that, in the most naive implementations of this model, additional memory is wasted (versus the delegation model) on each clone for the parts that have stayed the same between prototype and clone. However, it is possible to provide concatenative behavior to the programming while sharing implementation and data behind-the-scenes; such an approach is indeed followed by Kevo..
An alternative quasi-solution to the problem of clones interfering with the behavior of the parent is to provide a means whereby the potential parent is flagged as being clonable or not. In MOO
MOO programming language
The MOO programming language is a relatively simple programming language used to support the MOO. It is dynamically typed and uses a prototype based object oriented system, with Syntax of programming languages roughly derived from the Algol programming language school of programming languages.... , this is achieved with the "f" flag. Only objects with the "f" flag can be cloned. In practice, this leads to certain objects serving as surrogate classes; their properties are kept constant to serve as initial values for their children. These children then tend to have the "f" flag not set.
Criticism
Advocates of class-based object models who criticize prototype-based systems often have concerns that could be seen as similar to those concerns that proponents of static type systems for programming languages have of dynamic type systems (see Datatype). Usually, such concerns involve: correctness
Correctness
In theoretical computer science, correctness of an algorithm is asserted when it is said that the algorithm is correct with respect to a program specification.... , safety
Safety
Safety is the state of being "safe" , the condition of being protected against physical, social, spiritual, financial, political, emotional, occupational, psychological, educational or other types or consequences of failure, damage, error, accidents, harm or any other event which could be considered non-desirable.... , predictability
Predictability
Predictability is the degree to which a correct prediction or forecast of a system's state can be made either qualitatively or quantitatively.... , and efficiency
Algorithmic efficiency
In computer science, efficiency is used to describe properties of an algorithm relating to how much of various types of resources it consumes. The two most frequently encountered are... .
On the first three points, classes are often seen as analogous to types (in most statically typed object-oriented languages they serve that role) and are proposed to provide contractual guarantees to their instances, and to users of their instances, that they will behave in some given fashion.
On the last point, efficiency, the declaration of classes simplifies many compiler
Compiler
A compiler is a computer program that transforms source code written in a programming language into another computer language . The most common reason for wanting to transform source code is to create an executable program.... optimizations that allow developing efficient method and instance variable lookup. For the Self language, much development time was spent on developing, compiling, and interpreting techniques to improve the performance of prototype-based systems versus class-based systems. For example, the Lisaac
Lisaac
Lisaac is the first compiled object-oriented programming language based on prototype-based programming concepts, with system programming facilities and design by contract.... compiler produces code almost as fast as C. Tests have been run with an MPEG-2 codec written in Lisaac, copied from a C version. These tests show the Lisaac version is 1.9% slower than the C version with 37% fewer lines of code.
The most common criticism made against prototype-based languages is that the community of software developer
Software developer
A software developer is a person or organization concerned with facets of the software development process wider than design and coding, a somewhat broader scope of computer programming or a specialty of project manager including some aspects of Software product management.... s is not familiar with them, despite the popularity and market permeation of JavaScript
JavaScript
JavaScript is a scripting language widely used for client-side web development. It was the originating Programming language dialect of the ECMAScript standard.... . This knowledge level of prototype based systems seems to be changing with the proliferation of JavaScript frameworks and increases in the complex use of JavaScript
JavaScript
JavaScript is a scripting language widely used for client-side web development. It was the originating Programming language dialect of the ECMAScript standard.... as "Web 2.0
Web 2.0
The term "Web 2.0" refers to a perceived second generation of web development and web design, that aims to facilitate communication, secure information sharing, interoperability, and collaboration on the World Wide Web.... " matures.
ECMAScript is a scripting language, standardized by Ecma International in the ECMA-262 Specification . The language is widely used on the World Wide Web, and is often confused with JavaScript or JScript, the two major Programming language dialect from which ECMAScript was standardized....
ActionScript is a scripting language based on ECMAScript. ActionScript is used primarily for the development of websites and software using the Adobe Flash Player platform , but is also used in some database applications , and in basic robotics, as with the Make Controller Kit.... (Used by Adobe Flash
Adobe Flash
Adobe Flash is a multimedia Platform created by Macromedia and currently developed and distributed by Adobe Systems. Since its introduction in 1996, Flash has become a popular method for adding animation and interactivity to web pages; Flash is commonly used to create animation, advertisements, and various web page components, to integrate... and Adobe Flex
Adobe Flex
Adobe Flex is a collection of technologies released by Adobe Systems for the development and deployment of cross-platform rich Internet applications based on the proprietary Adobe Flash platform.... )
ECMAScript for XML is a programming language extension that adds native XML support to ECMAScript . The goal is to provide an alternative to Document Object Model interfaces that uses a simpler syntax for accessing XML documents....
JavaScript is a scripting language widely used for client-side web development. It was the originating Programming language dialect of the ECMAScript standard.... (first named Mocha, then LiveScript)
JScript is the Microsoft dialect of the ECMAScript scripting language specification.JavaScript , JScript, and ECMAScript are very similar languages....
The Falcon Programming Language, with Falcon P.L., Falconpl or Falcon being short names, is an open source, multi-paradigm programming language programming language....
Io is a pure Object-oriented programming Computer programming Programming language inspired by Smalltalk, Self , Lua , Lisp , Act1, and NewtonScript....
Lisaac is the first compiled object-oriented programming language based on prototype-based programming concepts, with system programming facilities and design by contract....
NewtonScript is a prototype based programming language created to write programs for the Newton platform. It is heavily influenced by the Self computer language, but modified to be more suited to needs of mobile and embedded devices....
Object Lisp was an object-oriented Lisp programming language computer programming languages designed by Lisp Machines, Inc. Object Lisp is an early example of Prototype-based programming.... by Gary Drescher of Lisp Machines
Lisp Machines
Lisp Machines, Inc. was a company formed in 1979 by Richard Greenblatt of MIT's MIT AI Lab to build Lisp machines. It was based in Cambridge, Massachusetts.... , Inc., 1985
Omega is a prototype-based programming programming language created by G?nther Blaschek in the spirit of Smalltalk. It does not have classes in the sense of Smalltalk and C++, but prototype as in Javascript, Self , Slate and Io ....
OpenLaszlo is an open source platform for the development and delivery of rich Internet applications. It is released under the Open Source Initiative-certified Common Public License....
In computer programming, Perl is a high-level programming language, List of programming languages by category, Interpreter , dynamic programming language.... , with the module
SmartFrog is an open-source software framework, written in Java , that manages the configuration, deployment and coordination of a software system broken into components....
Tcl is a scripting language created by John Ousterhout. Originally "born out of frustration"?according to the author?with programmers devising their own languages intended to be embedded into applications, Tcl quickly gained wide acceptance on its own and is generally thought to be easy to learn, but powerful in competent hands.... with the snit
Snit
Snit is an object-oriented extension to the Tcl programming language. Snit is a recursive acronym that stands for "Snit's Not Incr Tcl." Snit is a pure Tcl Object and megawidget system.... extension.
Class-based programming, or more commonly class-orientation, refers to the style of object-oriented programming in which inheritance is achieved by defining classes of objects, as opposed to the objects themselves .... (contrast)
A programming paradigm is a fundamental style of computer programming. . Paradigms differ in the concepts and abstractions used to represent the elements of a program and the steps that compose a computation .... s
Differential Inheritance is a common inheritance model used by Prototype-based programming programming languages such as JavaScript, Io programming language and NewtonScript....