Newbie Question Re: Prototypes

Stefan Matthias Aust sma at kiel.netsurf.de
Wed Feb 25 19:30:27 UTC 1998


>What are prototypes and how would they be used in Squeak?

In Smalltalk, every object has a class that describes the structure and
behavior of this instance. For example, the class Point describes how point
object objects are added, compared or asked for their x or y coordinate.
The Point class also holds the information, that every new point has two
instance variables called x and y that will store the point's coordinate.

Classes are also used to create new objects (so called instances) based on
these information. You can see them as a blue print (or a factory) for new
obejcts.

In a prototype based language, there are no classes. All objects know
theirself how to behave. Each object is unique and independent of all other
objects. 

But there has to be some way to create new objects, even without classes.
You simply take another object and make a copy of it (a so called clone).
These template objects are called prototypes, as they're acting as a common
instance of that kind of objects.

But is this really useful? It depends. Sometimes, you're dealing with a lot
of objects which are all different. Look for example at a user interface.
Each button has a special task to fulfill, each input field holds a
different text. Every new menu is very special. One solution might be to
create a class for each special object and make exactly one instance. But
using prototypes you can customize - without bothering about classes is
much easier.

Generally, prototype-based languages are more direct and easier to
understand because they lack the meta object layer. And with prototypes,
you can easily emulate classes. The other way round is also possible but
more difficult.

bye
--
Stefan Matthias Aust  //  Ride on - through the night - ride on





More information about the Squeak-dev mailing list