Next: , Previous: Delegation, Up: Objects


2.1.3 Prototypes

As mentioned before, Sheeple does not have a distinct concept of classes as type definitions. Nevertheless, it is often the case while writing an object-oriented application that a single object might be used as an exemplar which many other objects use as a parent. An object that is mainly created with the purpose of having other objects inheriting data and behavior from it is called a “prototype”.

In Sheeple, a prototype can be any object, and all the usual rules for them apply. On the other hand, Sheeple provides certain facilities that make dealing with this prototype pattern simpler. The most important of these is the macro DEFPROTO. This macro is a wrapper around OBJECT that adds some convenience sugar such as an easier method for defining property values and accessors, options for objects, and automatically binding the new new object to a variable (the “prototype name”). Additionally, DEFPROTO supports the redefinition of the same object by simply re-evaluating a DEFPROTO form that refers to the object, which will take care of adding/removing any properties. This is supported by automatically calling REINIT-OBJECT if the prototype already existed.

By convention, prototypes in Sheeple use a naming scheme where the name of the prototype is wrapped in = signs (“=FOO=”). This is purely a naming convention, and all built-in prototypes in the Sheeple system are named in this way.