"COMPUTER POWER TO THE PEOPLE! DOWN WITH CYBERCRUD!" - Theodor Nelson
Friday, September 19, 2003
More Prototypical Objects
Sam Griffth sent me this kick ass explanation. ENJOY!
First off, it is possible to use a class based OO system to implement a
prototypical OO system and vice versa. One of the very first Smalltalk
programs created at PARC was a prototypical OO system. ThingLab used
prototypical objects in it's domain space to do it's work, but it itself was
implemented with classes and prototypical objects at the same time. Part of
the SELF research idea to use prototypical objects was derived from the SELF
team having seen the ThingLab work. Link to ThingLab papers and version
ported to Squeak, including the original PARC paper:
As for what a prototypical OO language gives you that you don't get in a
class based one is conceptual purity and all messaging is based on
delegation. Classes are really about type definition and organization of
the instances of that type. With prototypes, you don't have a class. You
just create one instance that you clone over and over again. And all the
instances made from it know it. Your parent is whomever you cloned from.
Your parent has methods that you may not have, so instead of looking to a
class as something different or special, you end up with just the object you
cloned from. No differentiation is made.
In a prototypical world, you start with one bootstrap object that knows how
to add/remove/run methods on itself and how to delegate to it's parent if it
has one. From that, you can clone it (call it c1), add new attributes to
the new cloned object, add methods to that new cloned object, clone c1 to
make c2, etc. Now when you do cloned to get c1, c1's parent was the
bootstrapObject, when you cloned c2 it's parent was c1. So when you send a
message to c2, if it doesn't have it, it delegates the lookup to c1 which
then will delegate it to bootstrapObject if needed, etc.
There is no need for classes in this model. It is much more like nature.
All mammals share traits that they inherited by being fertilized from an egg
and sperm, but there really is no 'class' of mammals. That is a man made
idea for our organization to show that we saw that the DNA is common and
they have common traits, etc. From the outside it looks like that you are
inheriting from the class of mammal that you are (human lets say), but what
really happens in the reproduction process is that the DNA from the mother
and father are cloned by the RNA bands and combined together in a process.
This makes a new specific kind of instance much like if I had a multiple
parents clone, which is possible in a prototypical OO system as well.
I hope all this makes sense.... Let me summarize....
Prototypical OO systems are based on cloning and delegation. A much simpler
model based all in instances.