Prototype based programming
Prototype-based programming is a style of object oriented programming. Prototype based porgramming encourages the programmer to focus on the behavior of some set of examples and only later worry about classifying these objects that are later used in a fashipn similar to classes.
Prototype based programming is also known as class-less, prototype-oriented or instance-based programming. Classless programming style is supported by the following programming languages.
There are two methods of constructing new objects in a prototype based systems.
In most of the 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. Not only data but also methods can be added or changed. Prototype based languages refer to both data and methods as "slots".
Protoype based systems allows the alteration of prototypes during runtime. Prototype-based programming is supported with the help of the following two language features
Advantages of Concatenation
Disadvantages of Concatenation
Disadvantages of Prototype based programming
(However the knowledge level of prototype based systems seems to be changing with the proliferation of javaScript frameworks and increases in the complex use of javaScript as Web 2.0 matures.)
Prototype based programming is also known as class-less, prototype-oriented or instance-based programming. Classless programming style is supported by the following programming languages.
- JavaScript,
- ActionScript,
- Lua
- Open Laszlo
There are two methods of constructing new objects in a prototype based systems.
- Cloning of an existing object
- ex nihilo ("from nothing") object creation
In most of the 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. Not only data but also methods can be added or changed. Prototype based languages refer to both data and methods as "slots".
Protoype based systems allows the alteration of prototypes during runtime. Prototype-based programming is supported with the help of the following two language features
- Delegation - the behavior sharing between objects is established through delegation pointer. Language runtime is capable of dispatching the correct method or finding the right peice of data simply by following a series of delegation pointers (from object to its prototype) until a match is found.
- Concatenation - pure prototyping, is also referred to as concatenative prototypes, 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).
Advantages of Concatenation
- Programmer can alter the copy without worrying about side-effects across other children of the parent.
- 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 slopt can be admitted.
Disadvantages of Concatenation
- Additional memory is wasted (versus the delegation model) on each clone for the parts that have stayed the same between prototype and clone.
Disadvantages of Prototype based programming
- 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.
- Classes no longer provides contractual guarantees to their instances and to users of their instances about their behaviour hence there could be issues w.r.t the following:
- Correctness
- Safety
- Predictability
- Efficiency - less compiler optimization can be performed in prototype based programming hence they are less efficient.
- Unfamiliarity - software developers have low knowledge level about the prototype based systems.
(However the knowledge level of prototype based systems seems to be changing with the proliferation of javaScript frameworks and increases in the complex use of javaScript as Web 2.0 matures.)
Comments
Post a Comment