|
Prototype-depending programming occurs as style & subset of object-oriented programming in which classes are not present, & behavior reuse (called inheritance in class-based languages) is handle cloning existing objects which serve when prototypes for the new ones. These are as well referred to as class-egalitarian, prototype-oriented, or even time-depending programming.
the original (& canonical) case of a image depending language is Self, but a class-egalitarian programming style has recently grown more & more popular, and has been adopted for the programming languages Cecil, JavaScript, NewtonScript, Io, MOO, REBOL, and many others.
Incentive
Sustaining class-depending languages, objects come in both general types. Classes define the basic layout & functionality of objects, & instances are "usable" objects based on the system of a particular class. Programming within such the language occasionally consists of designing classes, & adding functionality to produce various cases that store & manipulate information.
A classes come collections of code for a objects, which come then a equivalent for everthing cases, whereas a cases are collections of memory holding the objects' information, which are then what distinguishes the children from either every more (the construct called state). This model works swell sustaining traditional compilers, which basically write code so develop that code manipulate information.
A single condition sustaining class-depending languages, in the opinion of advocate of paradigm depending programming, is that software seldom remain electrostatic in the period of development. When systems develop, their original class stuctures typically turn into short. A classes must exist as extended using supplementary code, negating occasionally of the advantages of object orientation. For a select few utilizes, it would become better in case computer program can vary a behaviour of the underlying classes. Within virtually all languages, a classes come but fixed at compile time and can does'nt exist as changed at runtime.
Prototypes and cloning
Instead of information-containing cases & code-containing classes, prototype-depending languages merely use at times objects. The paradigm models starts by having at least of these minute object loaded, & newly objects come created by cloning existent ones. Cloning an object creates an completely fresh of these that starts by using a equivalent default behaviours when its original.
Instead of with the pointer to the class, newly objects contain the pointer to the object that created the children. It is largely empty, & simply run growing within memory whenever changed. This is different from either class-depending object-oriented languages, in which every case of the class normally sets aside the known total of memory. Extra information may be added to any object at any point at runtime. Since objects develop equally required, anything may be added to the babies. As the matter of fact, each object around such a rules tends to exist as different than each more, non sole within the information themselves, however in what information come existence recorded. These are too significant to note that non merely information however likewise methods may be added or even changed. For this understanding virtually all image depending languages refer to two information & methods when "slots".
Although image depending languages merely require to run sustaining of these object, it generally provide the choice of basic objects for convenience. In a main these objects tend to keep close at hand method definitions just, relying on the coder to add the information every bit required. E.g., the Point object that may record positions inside both dimensions will contain methods for adding & subtracting points, but not include a x & y definitions. A coder would instead stand to add these to every fresh copy.
This leads to a bit of increased flexibility. Bugs within existent object methods may be fixed by sending a newly code (in a form of bars) into the appropriate "slot". Likewise, any object may be turned into 1 that handles remote invocation by replacing methods in the equivalent fashion. Class project is simplified, because a "class" definitions may become changed at any point eventually, & inside any application (of these application may fix bugs in a objects it utilizes for itself, & the changes might non be seeable to others).
Pure prototypes
Under pure prototyping, no pointers to the "parent". A "mother" object is copied exactly, however given the different title (or even information). It may be in comparison biological mitosis. Methods & attributes come just duplicated when-is. A drawback is that memory is consumed for every copy for a area that come the equivalent. A benefit is that a single might vary a copy forswearing worrying all about side-results in the more kids of the parent. Pure prototyping can besides simplify implementation, assuming memory is non the hardly resource.
Criticism
From either a point of review of advocate of statically typewritten programing language, correctness, safety, efficiency and predictability are more significant than a minor increase within flexibility from either ability to modify code at redo-period.
The particularly proficient lesson of this is the extensive apply of JavaScript to implement Mozilla Firefox's user interface & its extensions. A JavaScript running off around a web browser has higher security access than the JavaScript objects embedded in webpage, however typically has to interact by owning untrusted objects. Around a non-statically-typed language, it may be quite hard to assure your family use a object your family believe professional people keep around & that the method you're calling does what you believe it does. Vocation the method that was replaced potty stimulator untrusted code to do at the higher security level. This has resulted within several security bugs.
Languages
Actor-Depending Simultaneous Language, ABCL: ABCL/1, ABCL/R, ABCL/R2, ABCL/c+
Agora
Cecil
Cel
ECMAScript a.k.a. ActionScript, DMDScript, JavaScript (first named Mocha, so LiveScript), JScript
Io
Lua
MOO
NewtonScript
Obliq
REBOL
Self
TADS
|
Brain
High-level, pure object-oriented, prototype-based, scripting language; Smalltalk-like syntax; some features borrowed from Scheme, Self, JavaScript. [Open Source, LGPL]
Prototype-based Languages
Text table compares about 20 languages, with links: Agora, Amulet, Cecil/Vortex, Cel, Garnet, GlyphicScript, Io, JavaScript, Kevo, Lua, Merlin, Moostrap, NewtonScript, Obliq, Omega, OScheme, Poe, Self, SK8.
Agora
OO prototype-based, reflective language, based on only message passing, a key trait of OO languages; it allows late-binding polymorphism, the key trait making possible incremental modifying of programs. Descriptions, papers, implementations: Smalltalk, C++, Java, Scheme; MiniMix.
OScheme
Small, embeddable interpreter, mostly Scheme R4RS conformant, with extensions: supports prototype-based object model, some POSIX system calls, compilable in secure mode.
NewtonScript Papers
Papers about and related to NewtonScript, the prototype-based language for Newton PDA.
Object-based PLs
By Rainer Blome. Alphabetized list with descriptions of, and links to, many prototype-based languages.
Mica
Was Poe: prototype inheritance language and OO virtual machine for building network-accessible programs for multiple programmers, users, agents. Persistence and garbage collection are automatic and transparent. [Open Source, GPL]
MLud
A runtime-extensible language built on top of SML/NJ designed for building collaborative environments. Supports dynamic delegation with multiple dispatch, several useful datatypes, inline ML, and checkpoint persistence.
Slate
Language-OS based on CLOS, Self, Smalltalk; Smalltalk syntax; libraries inspired by Common Lisp, Dylan, Strongtalk (strong typing). Descriptions, programming manual, tutorials, summaries, bulletin board Swiki, CVS. [Open Source, LGPL]
|