CSC/ECE 517 Fall 2010/ch4 4e ms: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
= '''Prototype Based Programming''' =
Object oriented programming styles are
==History==
* Eleanor Rosch introduced [http://en.wikipedia.org/wiki/Prototype_theory Prototype theory] in mid-1970's.
* Borning proposed a description of a classless language in which new objects are produced by copying and modifying prototypes in 1986.[1]
*  Development of prototype based systems which did not rely much on advance categorization and classification, but tried to make concepts in the problem domain as tangible and intuitive as possible, Self(Ungar and Smith 1991) uses a mechanism called delegation, Omega (Blaschek 1991; Blaschek 1994), Kevo (Taivalsaari 1992; Taivalsaari 1993b), GlyphicScript (Schwartz and Lentczner 1994), NewtonScript (Smith, Lentczner, Smith, Taivalsaari, Ungar 1994)
* The classless model of object oriented programming [in 1980s] brought forward several issues related to class based programming and proposed various solutions based on the use of prototypes.


==Introduction==


The sun is pretty big,<ref>Miller, Edward. ''The Sun''. Academic Press, 2005, p. 1</ref>
===Why Prototype based solutions?===
but the moon is not so big.<ref>Brown, Rebecca. "Size of the Moon," ''Scientific American'', 51(78):46</ref>
* Prototypical instances and cloning is a simpler programming model. A single class plays many roles (instance descriptors, method libraries, support for encapsulation, sharing, reuse, archictecture of programs).  
The sun is also quite hot.<ref>Smith, John. ''The Sun's Heat''. Academic Press, 2005, p. 2.</ref>
* Prototypes offer new capabilities to represent knowledge that are difficult to grasp in class-based languages, ie. different objects of same family with different structures and behaviours, exceptional objectrs, objects with viewpoints and hsaring at the object level, incomplete objects that can be classified.
* Real world - objects - classes which can be viewed as sets or prototypes
e.g. First view of sets name of class Car refers to SET of all cars and each car is member/instance of class
Second view name of class refers to typical car or concept of car that has all properties that all cars have in common
 
===Comparison between prototype-based languages and class-based languages===
 
{| class="wikitable" border="1" style="text-align: center; width: 900px; height: 200px; margin-left:60px;"
|-
! Class-Based (Java)
! Prototype-Based (JavaScript)
|-
| Class and instance are distinct entities.
| All objects are instances.
|-
| Define a class with a class definition; instantiate a class with constructor methods.
| Define and create a set of objects with constructor functions.
|-
| Create a single object with the new operator.
| Same.
|-
| Construct an object hierarchy by using class definitions to define subclasses of existing classes.
| Construct an object hierarchy by assigning an object as the prototype associated with a constructor function.
|-
| Inherit properties by following the class chain.
| Inherit properties by following the prototype chain.
|-
| Class definition specifies all properties of all instances of a class. Cannot add properties dynamically at run time.
| Constructor function or prototype specifies an initial set of properties. Can add or remove properties dynamically to individual objects or to the entire set of objects.
|-
|}
 
==Classification==
Prototype based languages can be classified in following categories.
*Primives of virtual maching underlying each language - Classifies language according to semantics of these primitves
*Group-oriented constructions provided in language - Classifies acc to level of abstractness of these constructions.
*Design and implementation:
**Purely prototype based: Self, Kevo, Taivalsaari, Agora, Garnetk **Moostrap, Omega, Obliq, NewtonScript
**Not Strictly prototype based: Object-Lisp, Yafool
**Languages mixing prototypes and classes:
 
 
==References==
* Borning A (1986), ''Classes versus Prototypes in Object-Oriented Languages'', IEEE Computer Society Press, [http://portal.acm.org/citation.cfm?id=324538 In Proceedings of the IEEE/ACM Fall Joint Conference].

Revision as of 01:07, 19 October 2010

Prototype Based Programming

Object oriented programming styles are

History

  • Eleanor Rosch introduced Prototype theory in mid-1970's.
  • Borning proposed a description of a classless language in which new objects are produced by copying and modifying prototypes in 1986.[1]
  • Development of prototype based systems which did not rely much on advance categorization and classification, but tried to make concepts in the problem domain as tangible and intuitive as possible, Self(Ungar and Smith 1991) uses a mechanism called delegation, Omega (Blaschek 1991; Blaschek 1994), Kevo (Taivalsaari 1992; Taivalsaari 1993b), GlyphicScript (Schwartz and Lentczner 1994), NewtonScript (Smith, Lentczner, Smith, Taivalsaari, Ungar 1994)
  • The classless model of object oriented programming [in 1980s] brought forward several issues related to class based programming and proposed various solutions based on the use of prototypes.

Introduction

Why Prototype based solutions?

  • Prototypical instances and cloning is a simpler programming model. A single class plays many roles (instance descriptors, method libraries, support for encapsulation, sharing, reuse, archictecture of programs).
  • Prototypes offer new capabilities to represent knowledge that are difficult to grasp in class-based languages, ie. different objects of same family with different structures and behaviours, exceptional objectrs, objects with viewpoints and hsaring at the object level, incomplete objects that can be classified.
  • Real world - objects - classes which can be viewed as sets or prototypes

e.g. First view of sets name of class Car refers to SET of all cars and each car is member/instance of class Second view name of class refers to typical car or concept of car that has all properties that all cars have in common

Comparison between prototype-based languages and class-based languages

Class-Based (Java) Prototype-Based (JavaScript)
Class and instance are distinct entities. All objects are instances.
Define a class with a class definition; instantiate a class with constructor methods. Define and create a set of objects with constructor functions.
Create a single object with the new operator. Same.
Construct an object hierarchy by using class definitions to define subclasses of existing classes. Construct an object hierarchy by assigning an object as the prototype associated with a constructor function.
Inherit properties by following the class chain. Inherit properties by following the prototype chain.
Class definition specifies all properties of all instances of a class. Cannot add properties dynamically at run time. Constructor function or prototype specifies an initial set of properties. Can add or remove properties dynamically to individual objects or to the entire set of objects.

Classification

Prototype based languages can be classified in following categories.

  • Primives of virtual maching underlying each language - Classifies language according to semantics of these primitves
  • Group-oriented constructions provided in language - Classifies acc to level of abstractness of these constructions.
  • Design and implementation:
    • Purely prototype based: Self, Kevo, Taivalsaari, Agora, Garnetk **Moostrap, Omega, Obliq, NewtonScript
    • Not Strictly prototype based: Object-Lisp, Yafool
    • Languages mixing prototypes and classes:


References