Darwin Help

Back to Index

ExtendClass

Function ExtendClass - Extend a class with additional fields

Calling Sequence  ExtendClass(newclass,oldclass,addarg1,...)
Parameters
NameTypeDescription

newclass symbolThe new class, oldclass with more fields
oldclass symbolThe base class being extended
addarg1 [symbol, type, anything]Description of additional arguments
Return Type  NULL
Synopsis ExtendClass creates a new class which has all the fields of the base class plus additionally defined ones. The result is a new class which automatically inherits all the methods of the oldclass and has additional fields described in the 3 and onwards arguments of ExtendClass. The description of each additional argument is a list of three values, the name of the new field, its type and, optionally, its default value. The default value is used when creating an object without it or when converting an object from oldclass to newclass. More precisely the following functions are created:
 

Old methodNew MethodComment

oldclassnewclassConstructor based on the oldclass constructor
oldclass_xxxnewclass_xxxsame rules as Inherit
yyy_oldclassyyy_newclassconversions from other classes to newclass
 oldclass_newclasswidening conversion
 newclass_oldclassnarrowing conversion
 

If some methods are not expected to be inherited from oldclass, they should either be unevaluated after calling ExtendClass or defined before calling ExtendClass.


ExtendClass does an implicit Inherit, so there is no point in doing an Inherit(newclass,oldclass). Any protection defined for the oldclass is inherited in the newclass. The newclass can Inherit other additional classes as usual.

Examples
> ExtendClass( DistTree, Tree, [height,numeric,0] );

See also CompleteClass,   Inherit,   objectorientation,   Protect