CSC/ECE 517 Fall 2010/ch5 5c ck

From Expertiza_Wiki
Revision as of 13:51, 30 October 2010 by Jazzman (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Dynamic Dispatch

Introduction

Dictionary Definition of Prototype: 'An original, full-scale, and usually working model of a new product or new version of an existing product'.[1]

"... the prototype approach in some ways corresponds more closely to the way people seem to acquire knowledge from concrete situations"[2]

Since the early period of implementation of Object Oriented Design (OOD), there have been two schools of thought concerning the best method of implementing OOD. The class approach, which is the static method of implementation. And the Prototype approach, which is the dynamic method of implementation.

The class based implementation of OOD is very rigid and favors a design first approach. The prototype based implementation of OOD favors a design as we go or iterative approach.

This article assumes that the reader is familiar with class based object oriented design and will focus mostly on the specifics of prototype based object oriented design. In doing so, we will also contrast the differences between the two and try to determine what is in the future.

Delegation

The mechanism for implementation of prototyping is called Delegation.[2]

'Operationally, delegation is the redirection of field access and method invocation from an object or prototype to another, in such a way that an object can be seen as an extension of another.'&nbsp[7]

Delegation is a process whereby an existing object dynamically searches for properties and methods first within itself, then if an match is not found, it delegates that search to its parent object. The parent then repeats the exact same delegation process until a match is found. Once a match is found the result is returned to the requester.

Simple Example
This example demonstrates two objects that I always want aligned on the same y axis, however I want them to be independent on the x axis.

Box remains as is but Point is changed

NOTE: In the above example Box.GetPoint() would also return [10,10]. When GetPoint() searches for X it starts at the original requestors level and uses delegation just like the method search for Box.GetPoint().

While delegation is simple in its design, we will see that it is also elegant. In that it opens the door for several different techniques which allow software developers to morph an existing object, into a much larger and more robust object. While still retaining the original objects simplicity.

Competing Approaches

Class Approach

New objects are made from predefined classes. A class definition must exist to create an instance of a class. When a class is changed, existing objects must be reconstructed and we also need to ensure that nothing else in the application requires the prior classes constructed behavior.

Prototype Approach

New objects are constructed by copying an existing object. After copying we are safe to change the class behavior knowing that we are independent of all other objects. Prototyping is dynamic allowing us to create a real world object as a single instance and then refactor it at run time.

  • We can add to it.
  • We can remove parts from it.
  • We can break parts out and move to a different location in the same delegation tree. Thereby extending the original behavior to more objects in the same object hierarchy.



Conclusion

The debate over which is better, class based OOD or prototype based OOD, has been around since the beginning of OOD. Prototype OOD appears to be gaining some mainstream ground, but it is still a long way from taking over traditional class based OOD. It is this authors opinion that this debate is ongoing and will exist in one form or another into the future. I believe that in the past 15 years, neither has proven to be advantagous in all circumstances over the other. I also believe that the evolution of some hybrid language features that attempt to bridge the gap will continue to evolve. I beleive that the future will at times lean in the direction of one or in the direction of the other, bull will never quite cuminate on one or the other.

References

[1] Yahoo Online Dictionary - Prototype