[转载&翻译]prototype oriented

来自http://www.brainyencyclopedia.com/encyclopedia/p/pr/prototype_oriented.html

Prototype-based programming is a style and subset of object-oriented programming in which classes are not present, and behaviour reuse (known as inheritance in class-based languages) is accomplished through a process of cloning existing objects which serve as prototypes. This model is also known as class-less, prototype-oriented, or instance-based programming.

基于原型的编程是面向对象编程的子系统和一种形式。在基于原型的编程中,类不是实时的,而且行为重用(通常认为继承自基于类的语言)是通过复制已经存在的原型对象的过程实现的。这个模型一般被认为是class-less, 面向原型,或者是基于接口的编程。

The original (and most canonical) example of a prototype-based language is the programming language Self developed by David Ungar and Randall Smith. However, the class-less programming style has recently grown increasingly popular, and has been adopted for the programming languages Cecil, Javascrīpt, Newtonscrīpt, Io, MOO, REBOL, Kevo, and several others.

基于原型的语言最初的(也是最经典的)例子是程序语言self,它是由David Ungar 和 Randall Smith开发的。但是class-less编程方式最近变得越来越受欢迎,并且被Cecil, Javascrīpt, Newtonscrīpt, Io, MOO, REBOL, Kevo, 还有一些其他的程序语言所采纳。

Contents

内容提要 

 

instances

Comparison with class-based models

With class-based languages, objects come in two general types. Classes define the basic layout and functionality of objects, and are "usable" objects based on the patterns of a particular class. In this model, classes act as collections of behaviour (methods) and structure which 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 behaviour on the one hand, and state on the other.

在基于类的编程当中,对象总共有两种类型。类定义了对象的基本布局和函数特性,而接口是"可以使用的"对象,它基于特定类的样式。在此模型中,类表现为行为和结构的集合,就接口持有对象的数据而言,对所有接口来说是相同的。区分规则因而首先是基于结构和行为,而后是状态。

Advocates of prototype-based programming often argue that class-based languages encourage a model of development which focus first on the taxonomy and relationships between classes. In contrast, prototype-based programming is seen as encouraging the programmer to focus on the behaviour of some set of examples and only later worry about classifying these objects into archetypal objects which are later used in a fashion similar to classes. As such, many prototype-based systems encourage the alteration of prototypes during runtime, whereas only a very few class-based object-oriented systems (such as the first dynamic object-oriented system, Smalltalk) allow classes to be altered during the execution of a program.

基于原型编程的主张者经常争论说基于类的语言提倡使用一个关注分类和类之间关系开发模型。与此相对,基于原型的编程看起来提倡程序员关注一系列对象的行为。。。。。。因为如此,很多基于原型的系统提倡运行时原型的修改,而只有极少数基于类的面向对象系统(比如第一个面向对象的系统,Smalltalk)允许类在程序运行时被修改。

Prototype-based programming is often associated with particular schools of thought in cognitive psychology which emphasize prototypes or exemplars as key attributes of the learning process.

基于原型的编程通常穿插在教授cognitive psychology的课程中,他强调prototypes 和 exemplars作为学习中的关键词。

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 [1] is an example of such a system.

因为绝大多数基于原型的系统势基于解释性的和强类型程序语言,这里要重点指出的是静态类型语言实现基于原型从技术上是可行的。用基于原型编程描述的Omega语言就是这样系统的一个例子。

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.[3]

Object construction

In class-based languages a new instance is constructed through the class's constructor and an optional set of constructor arguments. The resulting instance is modeled on the layout and behaviour 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 ("from scratch") object creation. While most systems support a variety of cloning, ex nihilo object creation is not as prominent.[2]

在基于原型的系统中构造对象有两种方法,通过复制已有的对象 或者通过扩展nihilo(空的?虚无?)对象创建,因为大多数系统提供了不同的复制方法,扩展nihilo对象的方式鲜为人知。

Systems which 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 behaviours of new objects without referencing existing objects.

提供 扩展nihilo对象创建 的系统允许对象从空白中创建而无需从已有的原型中复制。这样的系统提供特殊的文法用以指定新对象的行为和属性,无须参考已存在的对象。

Cloning refers to a process whereby a new object is constructed by copying the behaviour 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 or resemblance) to its prototype, and changes in the prototype cause corresponding changes to be apparent in its clone. Other system, such as the

复制指一个新对象通过复制一个已经存在的对象(就是他的原型)来构造自己的过程。于是新的对象拥有原来对象的所有属性,从这一点出发新对象的属性可以被修改。在某些系统中,子对象持有一个到它原型的直接链接(经由授权或类似方式)。并且原型的改变同样会导致它的副本的变化。。其他系统中,如类Forth的程序语言,Kevo在此情况下不传播原型的改变,而遵循一个更加连续的模型,其中被复制的对象改变不会通过他的副本传播。

dispatching to 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 behaviour-sharing behaviour between objects is thus 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 ammended over time without re-arranging the structure of its associated class 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".

Delegation

 

In prototype-based languages which use delegation the language runtime is capable of

在使用委托的基于原型的语言中,运行时语言可以仅仅通过循着一个序列的指针直到找到匹配这样的方式来定位属性或者寻找寻找正确的数据。所有这些 建立行为共享的行为 需要的是委托指针。不像是基于类的面向对象语言中类和借口的关系,原型和他的分支之间的关系并不要求子对象有相似的内存结构,因为如此,子对象可以继续修改和...而无须像基于类的系统那样整理结构。还有一个要提到的地方是,不仅仅是数据,方法也能被修改。因为这个原因,大多数基于类型的语言把数据和方法提作"slots"

Concatenation

Under pure prototyping -- which is also referred to as concatenative prototypes and is exemplified in the Kevo programming 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). This process can be compared in some ways to biological mitosis. Methods and attributes are simply duplicated as-is.

在纯粹的原型--又被称作concatenative原型 Kevo语言为例--中 没有到被复制的原型对象的指针或链接。原型对象以重新给定名字(或引用)的方式被确实的复制了。这个过程类似于生物学上的分裂,属性和方法被原样复制。

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.

concatenative的坏处包括传播变化到整个系统的难度;如果一个变化作用到某个原型,它不会立即或者自动的对它的所有副本生效。然而Kevo提供了额外的在对象系统中传播变化的方式。这种方式是基于他们的相似性(所谓的family相似)而非像委托模型具有代表性的那样源自分类学。

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 behaviour to the programming while sharing implementation and data behind-the-scenes; such an approach is indeed followed by Kevo.[4]

另外一个坏处是在这个模型的大多数自然的实现下,每一个副本上都有额外的内存被浪费掉了(相对委托模型而言),因为副本和原型之间有相同的部分存在。Datatype). In particular, those concerns revolve around: correctness, safety, predictability and efficiency.

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

In regard to the first three points, classes are often seen as analogous to types (and indeed, in most statically typed object-oriented languages they serve that role) and are proposed to provide contractual guarantees to their instances and users of their instances that they will behave in a given fashion.

On the last point, efficiency, the declaration of classes simplifies many compiler optimizations that allow the development of efficient method and instance variable lookup. In the case of the Self programming language, much development time has been spent on the development of compilation and interpretation techniques to improve the performance of prototype-based systems versus their class-based competitors.

Finally, perhaps the most common criticism leveled against prototype-based languages is that the community of software developers is not familiar with them, despite the popularity and market permeation of Javascrīpt. Further, as prototype-based systems are relatively novel, and few and far between, best practices for software development using them have not become widespread.

ABCL/1, ABCL/R, ABCL/R2, ABCL/c+

Languages

Computer programming/Object oriented programming

Further reading

has more about this subject:
  • (1999) James Noble (ed.), Antero Taivalsaari (ed.), Ivan Moore (ed.) Prototype-Based Programming: Concepts, Languages and Applications, Springer-Verlag. ISBN 981-4021-25-3.
^  Section 2.8 (pg.177). Günther Blaschek, Omega: Statically Typed Prototypes
^  Section 1.2 (pg.17). Chistophe Dony, Jacques Malenfan, Daniel Bardou, Classifying Prototype-based Programming Languages
^  Section 1.1 (pg.14). Antero Taivalsaari, Classes vs. Prototypes: Some Philosophical and Historical Observations
  • Abadi, Martin, Luca Cardelli. A Theory of Objects, Springer-Verlag. ISBN 0-387-94775-2.

^  Antero Taivalsaari. Kevo, a prototype-based object-oriented programming lnaguage based on concatenation and module operations. Technical Report Report LACIR 92-02, University of Victoria, 1992. 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值