What Is a Web Design Prototype?
Prototype programming (English: prototype-based programming), or prototype programming, prototype programming, is a subsystem and a way of object-oriented programming. In prototyping, classes are not real-time, and behavioral reuse (often considered to be inherited from a class-based language) is achieved through the process of copying an existing prototype object. This model is generally considered to be classless, prototype-oriented, or instance-based programming.
- The original (and most classic) example of prototyping is the programming language Self, which was developed by David Ungar and Randall Smith. But classless programming has become more and more popular lately, and has been adopted by JavaScript, Squeak (when using the observer framework to operate Morphic components), Cecil, NewtonScript, Io, MOO, REBOL, and some other programming languages. [1]
- There are two types of objects in category-based programming. Classes define the basic layout and functional characteristics of objects, while interfaces are "usable" objects that are based on the style of a particular class. In this model, a class behaves as a collection of behaviors and structures, and as far as the data held by the interface is concerned, it is the same for all interfaces. Distinction rules are therefore first based on structure and behavior, then state.
- Proponents of prototyping often argue that class-based languages advocate the use of a model that focuses on classification and relationships between classes. In contrast, prototyping seems to encourage programmers to focus on the behavior of a series of object instances, and then care about how to divide these objects into recent prototype objects that are used in a similar way, rather than into classes. Because of this, many prototype-based systems advocate modification of the runtime prototype, and only a few class-based object-oriented systems (such as Smalltalk, the first dynamic object-oriented system) allow classes to be modified while the program is running.
- Prototype programming is often associated with a particular school of thought in cognitive psychology, and also emphasizes prototypes and exemplars as keywords in the learning process.
- Considering that most prototype-based systems are based on interpreted and dynamically typed programming languages, it is important to point out here that it is technically feasible to implement prototype-based statically typed languages. The Omega language described in prototype-based programming is an example of such a system. Although Omega is not completely static according to the Omega website, its compiler sometimes uses static binding to improve the efficiency of the program when possible.
- In a class-based language, a new instance is constructed with a class constructor and optional parameters to the constructor, and the resulting instance is modeled by the behavior and layout selected by the class. There are two ways to construct objects in a prototype-based system, either by copying existing objects or by extending nihilo (empty) objects, because most systems provide different methods of copying, and little is known about how to extend nihilo objects.
- A system that provides extended nihilo object creation allows objects to be created from blanks without having to copy from existing prototypes. Such systems provide special grammars to specify the behavior and attributes of new objects without having to refer to existing objects. In many prototype languages, there is usually an Object prototype with methods that are commonly needed. It is used as the final prototype for all other objects. Extending nihilo object creation guarantees that new objects are not polluted by the namespace of the top-level object. (In JavaScript, this can be done using the null prototype, ie Object.create (null)).
- Cloning refers to the process by which a new object constructs itself by copying an existing object (that is, its prototype). Then the new object has all the properties of the original object. From this point on, the properties of the new object can be modified. In some systems, a child object holds a direct link (via authorization or similar) to its prototype. And a change in the prototype will also cause a change in its copy. In other systems, such as Forth-like programming languages, Kevo does not propagate changes in the prototype in this case, but follows a more continuous model in which changes to the copied object are not propagated through his copy.
// Example of true prototypal inheritance style // in JavaScript. // "ex nihilo" object creation using the literal // object notation (). var foo = {name: "foo", one: 1, two: 2}; // Another "ex nihilo" object. var bar = {three: 3}; // Gecko and Webkit JavaScript engines can directly // manipulate the internal prototype link. // For the sake of simplicity, let us pretend // that the following line works regardless of the // engine used: bar .__ proto__ = foo; // foo is now the prototype of bar. // If we try to access foo's properties from bar // from now on, we'll succeed. bar.one // Resolves to 1. // The child object's properties are also accessible. bar.three // Resolves to 3. // Own properties shadow prototype properties bar.name = "bar"; foo.name; // unaffected, resolves to "foo" bar.name; // Resolves to "bar"
- Here is an example in JavaScript 1.8.5 and above
var foo = {one: 1, two: 2}; // bar. [[prototype]] = foo var bar = Object.create (foo); bar.three = 3; bar.one; // 1 bar.two; // 2 bar.three; // 3
- In a prototype-based language that uses delegates, the runtime language can simply locate attributes or find the correct data by following a sequence of pointers until a match is found. All of these behaviors that establish behavior sharing require delegate pointers. Unlike the relationship between classes and interfaces in a class-based object-oriented language, the relationship between the prototype and its branches does not require similar memory structures for the child objects, because the child objects can continue to modify and ... Organize your structure like a class-based system. Another thing to mention is that not only the data, but methods can also be modified. For this reason, most type-based languages refer to data and methods as "slots".
- There is no pointer or link to the copied prototype object in a pure prototype, also known as a concatenative prototype (taking Kevo as an example). The prototype object is actually copied by re-given the name (or reference). This process is similar to biological division, with attributes and methods being copied as is.
- The benefits of this include that the author of the object can modify this copy without worrying about side effects on other subclasses of this parent. A further advantage is that the consumption of the lookup attribute operation is greatly reduced compared to authorization, and authorization lookup must traverse the entire delegation chain to determine that it does not exist.
- The disadvantages of Concatenative include the difficulty of propagating changes to the entire system; if a change is applied to a prototype, it will not immediately or automatically take effect on all its copies. However, Kevo provides additional ways to propagate changes in the target system. This approach is based on their similarities (so-called family similarities) rather than derived from taxonomy as representative models of delegations.
- Another disadvantage is that under most natural implementations of this model, extra memory is wasted on each copy (as opposed to the delegated model), because the same part exists between the copy and the prototype. However, programming that provides concatenative behavior in shared implementations and background data is possible. This practice is followed by Kevo.
- Those who often criticize the support of class-based object models based on prototype systems often have concerns about similar static type systems over dynamic type systems. Often these concerns are: correctness, security, predictability, and efficiency.
- In the first three points, classes can be viewed as equivalent to types (most static languages follow this rule) and provide a contract that guarantees their instances, while users of these instances are guaranteed to behave in specific scenarios.
- On the last point, efficiency, class declarations simplify the organization of the compiler, allowing the development of efficient methods and instance variable lookups. For the Self language, most development time is spent developing, compiling, and interpreting techniques to improve prototype-based systems versus class-based systems. For example, Lisaac produces almost as fast code as C. The test was derived from the Lisaac version of the MPEG-2 encoder, which was copied from a C version. Testing shows that Lisaac version is 1.9% slower than C version, but the number of lines of code is 37% less. However, C is not an object-oriented language, but a procedural language. Lisaac may be more telling than the C ++ version.
- The most common criticism of prototype-based languages comes from the community of software developers who dislike it, despite the popularity and market of JavaScript. The level of understanding of prototype-based systems seems to have changed due to the widespread use of JavaScript frameworks and the complex applications of JavaScript for Web 2.0. It is likely that for these reasons, the fourth edition of the ECMAScript standard began to seek to make JavaScript provide class-based construction, and the sixth edition of ECMAScript provided "class" as a syntactic sugar on top of the original prototype architecture to provide construction Objects and another syntax for handling inheritance.
- ABCL: ABCL / 1, ABCL / R, ABCL / R2, ABCL / c +
- Agora
- Cecil
- Cel
- ColdC
- ECMAScript
- ActionScript, used by Adobe Flash and Adobe Flex
- E4X
- JavaScript
- JScript
- Falcon
- Io
- Ioke
- Lisaac
- Logtalk
- LPC
- Lua
- MOO
- Neko
- NewtonScript
- Obliq
- Object Lisp
- Omega
- OpenLaszlo
- Perl, with the Class :: Prototyped module
- R, with the proto package
- REBOL
- Self
- Seph
- SmartFrog
- TADS
- Tclwith snit extension