previous chapter contents page top page next chapter

AbstractClass

January 21, 1994

Defined in Class.Def 
Abstract
Inherits from Object, Cited
Uses extra
No translation



Class Description

Class AbstractClass provides the underpinnings for class Class. Although there are a few methods that are generally useful to all programmers, most of the methods of this class are useful only for developers of system programs such as ObjectMaker. Most programmers can safely ignore most of the details of class AbstractClass.

Remember that if the documentation and the software (especially the definition files) disagree, always trust the software.

Using an AbstractClass Object

The AbstractClass class is a direct descendant of class Object. Class AbstractClass defines many fields that are used to specify details of the objects of the classes they represent, including the number of fields and methods defined by the class and information about its superclasses.

Unless you're creating a highly specialized tool or are extremely curious, you'll never create an abstract class object in your packages, nor will you define one in an instance definition file. You will probably work more directly with class Class (if at all).

Programming Information

Instantiate: rarely



Subclass: rarely

Call its methods: rarely

Fields defined by class AbstractClass

The AbstractClass class defines the following fields:

Field Type Description
Inherited from Cited
citation Citation citation for the class
Defined by AbstractClass
telescriptName ClassName Telescript name of the class
number Unsigned Index into class table
implSuperCount Unsigned Number of superclasses providing implementation
implSuperOffset Unsigned Offset to table of implementation superclasses
methodCount Unsigned Number of methods defined for class
methodOffset Unsigned Offset to table of methods
classFlags UnsignedShort "miscellaneous flags"
wirelineBaseClassNumber UnsignedByte Wireline-related
wirelineDepth UnsignedByte Wireline-related

Method Descriptions

Object Management

overrides Init

Call: rarely
Override: sometimes

When a new object is created, the system calls Init to allow the new object to set up its fields. The default implementation of Init [to be written].

You should override Init if your class defines any fields that should be set to initial values when a new object is created. See the description of Object_Init for more information.

Class Membership

IsMember

operation IsMember(possibleMember: Object): Boolean

Call: rarely
Override: rarely

Call IsMember to test whether the given object is an instance of the class passed in the first parameter. If the object is an instance of the class, IsMember returns true.

A newer method that does the same job is Object_Implements, which you should use instead of IsMember. This is the declaration for Implements:

operation Implements(classNumber: Object): Boolean, intrinsic

Implements tests whether self is an instance of class classNumber.

IsSubMember

operation IsSubMember(possibleMember: Object): Boolean

Call: rarely
Override: rarely

Call IsSubMember to test whether the given object is an instance of a subclass of the class passed in the first parameter. If the object is an instance of a subclass of the class, IsSubMember returns true. SEEMS TO BE GONE.

ClassImplements

operation ClassImplements(classNumber: LongInt): Boolean

Call: rarely
Override: rarely

The system calls ClassImplements to test whether the class specified by the first parameter implements the interface defined by the given class. If so, ClassImplements returns true.

The system defines a symbol for every class that consists of the name of the class followed by an underscore. For example, there's a Button_ symbol which is the class number for the button class. When you create your own class, this symbol is generated automatically. You'll usually pass one of these system-defined symbols for the classNumber parameter.

EachInstance

operation EachInstance(proc: EachProcPtr; params: Pointer): Object; noFail

Call: sometimes
Override: sometimes

Call EachInstance when you want to invoke a function repeatedly for every instance of the class. If you call EachInstance, you must also define the iterative function that will be called for each object, then pass a pointer to that function in the proc parameter. If you want to send any parameters to your iterative routine, pass a pointer to the parameters in params when you call EachInstance.

EachInstance keeps calling the iterative function as long as the iterative function returns nilObject and there are still objects that haven't been processed. When the iterative function returns an object ID, EachInstance stops calling the iterative function and exits. This is useful if you want to stop iterating when your iterative function fulfills some condition, such as successfully completing a search.

The routine that's called for each object should be declared like this:

Private ObjectID IterativeProc (ObjectID theObject, void *params)

WARNING! You must use the Private specifier when you declare your iterative function. If you fail to do so, you'll get no warning from any tools during the build process, but your software will fail in an unpredictable way, you'll feel bad, you might miss the They Might Be Giants concert, and you'll have to have to ask embarrassing questions of technical support people.


The theObject parameter contains the object that's currently being processed. EachInstance will pass the params parameter unchanged each time IterativeProc is called.

FindInstanceByName

operation FindInstanceByName(matchName: String): Object, noFail;

Call: sometimes
Override: rarely

Call FindInstanceByName to search for an object of the given class whose name is the same as matchName. If a matching object is found, it's returned as the function result. If no matching object is found, FindInstanceByName returns nilObject.

FindByName

operation FindByName(name: String): Object, noFail;

Call: rarely
Override: rarely

Call FindByName to search for an object of a subclass of the given class whose name is the same as name. If a matching object is found, it's returned as the function result. If no matching object is found, FindByName returns nilObject.

Operations and Methods

Count

attribute Count: Unsigned, readOnly, safe;
// operation Count: Unsigned

Call: rarely
Override: rarely

The system calls Count to get the number of methods that are implemented by the class. Count simply returns the value of the object's methodCount field.

xOperations

operation xOperations(minAccessibility: Signed; intrinsicFlag: 
Boolean): Object

Call: rarely
Override: rarely

{Figure out what happened to this.}

Every class defines the operations that it can execute, and every operation includes an accessibility level. The accessibility determines whether the operation will be presented in menus in the Magic Script editor; only operations at the Safe and Common level can be used from Magic Script.

The system calls xOperations to create a list of operations in the class that have the minimum accessibility passed in minAccessibility. This method is mainly used by the Magic Script system, which calls xOperations with a value for minAccessibility that specifies all Safe and Common operations.

The accessibility of operations is usually specified in the class's definition file. Here's an example of how make an operation available to Magic Script:

method CanDo: Unsigned; Safe; Common

The system defines these accessibility levels and symbols for each level:

/* accessibility for operations */
#define accessibilityPrivate0/* default */
#define accessibilityDangerous1
#define accessibilitySafe2
#define accessibilitySafeCommon3

Magic Script users can also call methods that aren't listed as Safe and Common. To do this, scripters hold down the Magic key while touching the "feature" zone in the script statement. This opens the keyboard and creates an insertion point. Scripters can then type the name of the desired method.

Version note: The name xOperations is likely to change to Operations in the future.

HasMethod

operation HasMethod(operationNumber: Unsigned; intrinsicFlag: Boolean): 
Boolean

Call: rarely
Override: rarely

The system calls HasMethod to test whether the class has a method, possibly defined by a superclass, that implements the given operation.

HasMethod returns true if the class defines its own implementation of the given operation. If intrinsicFlag is true and the class doesn't define its own implementation, HasMethod returns false. If intrinsicFlag is false and the method is implemented by one of the class's superclasses, HasMethod also returns true.

AddMethod

operation AddMethod(operationNumber: Unsigned; codeOffset: Unsigned; 
code: Object; version: Unsigned; intrinsic: Boolean; patching: 
Boolean)

Call: rarely
Override: rarely

The system calls AddMethod to add a new method to the class. The method implements the specified operation, and the codeOffset parameter indicates the location of the code for the method. The class object is enlarged to accommodate the information for the new method, and the appropriate fields of the class object are updated.

MethodInstalled

operation MethodInstalled(methodIndex: ulong): Boolean

Call: rarely
Override: rarely

The system calls MethodInstalled to test whether the given method is installed in the class's method table.

SetMethodOffset

operation SetMethodOffset(methodIndex: Unsigned; offset: Unsigned)

Call: rarely
Override: rarely

The system calls SetMethodOffset to set the offset in the class's method table to the given value.

MakeGlobals

operation MakeGlobals()

Call: rarely
Override: rarely

When the class object is created, the system calls MakeGlobals to allocate space for the class variables and initialize them to zero. MakeGlobals also sets up the class object's globalData field to point to the class variables. <<<AbstractClass defines this as a no-op, so somebody should override.>>>

Debugging and Testing

Validate

overrides Validate

Call: rarely
Override: sometimes

AbstractClass_Validate provides a routine for subclasses, such as the Class class, to use for validity checking. AbstractClass_Validate calls its inherited implementation, which is Object_Validate. You should override Validate if you want objects of your class to perform any additional validity checking. See the description of the Validate method in the chapter on class Object for more information.