CSC/ECE 517 Fall 2010/ch1 4e dj

From Expertiza_Wiki
Revision as of 01:55, 30 October 2010 by Djfreema (talk | contribs) (Re worded stuff)
Jump to navigation Jump to search

Introduction

One of the key tenants of object oriented programming is the ability to specify common attributes for like objects. There are two main ways to do this. The first is by enumerating the elements that are in common, while the second involves defining objects in terms of other objects. Each allows the programmer to specify relationships between objects in their program, but the methods for doing this are radically different. The later method (using like objects) is refereed to as Prototype-based, while the former is Class or Set based.

Prototypes vs. Sets

When defining like behavior, the first method of doing this is by listing all the like components as you define the class. This can be done in a few different ways:

  • Abstract items in a class definition serve as placeholders that are to be implemented by all implementing classes. These can be methods, fields, or accessors. A class that has abstract items is called an abstract class.
  • Interfaces are a type of abstract class that only defines abstract methods. These classes are used as an answer to multiple inheritance in languages such as Java. Interfaces allow a behavior contract to be used to specify how objects interact. A using piece of code can use any implementing object that follows the contract.

However, the second method, prototyping, does not explicitly define any relationships. Instead, new objects are created by taking a object that is to be used as the prototype and extending the new object to change its functionality.

Creation using each method

A class can be created through its constructor. This restricts creation to explicit calls to the new method of the class, and prevents changing the objects behavior after the object is instantiated.

A prototype may be created either [[ex nihilo]http://en.wikipedia.org/wiki/Ex_nihilo#Computer_science] or by cloning another class.

Inheritance in each method

A class based design requires that all relationships are created explicitly in the source. This means that for a class to be a child of another, that relationship must be explicitly stated in the source at compile time.

An object may have its functionality extended during execution by inclusion of a prototype. This means that a object can be given any aspect while the code is executing. See Unbounded Polymorphism

Negatives of Prototype based programming

Compilers written for prototype languages are more complex than those written for class based languages. This raises concerns over efficiency at run time.

References

http://www.c2.com/cgi/wiki?PrototypeBasedProgramming http://en.wikipedia.org/wiki/Prototype-based_programming