Object Specification Sheet


Portable Object Compiler (c) 1996, 97 by Stes & Lerman. All Rights Reserved.

Object is the superclass of all classes. Methods implemented here are inherited by all Objective C classes.

Method Types

Class Management

Creating, Copying and Freeing

Identity

Comparing

Responding to Methods

Blocks

Error Handling

Method Lookup

Method Performing

Printing

Version

Archiving

AsciiFiler Methods

Methods



initialize

+ initialize

Every class in the application, receives an initialize message when the program starts. By default this method doesn't do anything. It can be overridden to do class initialization.

Note that all classes are guarantueed to receive initialize, before any other message is sent. Other runtimes differ with ours in this respect, that initialize is sometimes sent to a class, just before an instance of that particular class is being used (as opposed to all classes receiving initialize, before any instance receives a message).

Note: In some runtimes, the equivalent functionality is called +load instead of +initialize.



subclasses

+ subclasses

Returns a OrdCltn of direct subclasses of the class that receives the message. If the class has no subclasses, then this method returns an empty OrdCltn (not nil). The class itself is not considered subclass of itself.

Note: This method is Portable Object Compiler only.

See also: +class, +superclass, +inheritsFrom:



poseAs:

+ poseAs : superClass

The poseAs: method permits to modify a supplied superClass (for which, for example, no source code is available) by substituting a direct subclass of superClass. It is normally used inside +initialize, but the Portable Object Compiler allows poseAs: to be used anywhere in the program.

+ initialize { [self poseAs:[Set self]]; return self; }
The example shows how the initialize of some subclass, called for example SubSet, can substitute SubSet for Set. Methods defined in SubSet override those defined in the superclass, and new methods from SubSet, will appear to have come from the Set class.

When performing a poseAs:, the following rules must be followed:

The Portable Object Compiler implementation of poseAs: differs from some other runtimes, since it allows poseAs: to happen, even after messages have been sent to instances of posing or impersonated class.

Implementation details:

Note: All Objective-C compilers provide this functionality (sometimes with restrictions on when the method can be called)



addMethodsTo:

+ addMethodsTo : superClass

The addMethodsTo: method permits to modify a supplied superClass (for which, for example, no source code is available) by adding the (instance and factory) methods of a direct subclass, to superClass. It is normally used inside +initialize, but the Portable Object Compiler allows addMethodsTo: to be used anywhere in the program.

The same restrictions apply as for poseAs: : the subclass needs to be a direct subclass of superClass and it may not add instance variables. However, unlike poseAs:, the subclass will not be substituted for the superClass for purposes as fileIn: etc. Also, (unlike poseAs:) when the subclass adds a method to the superClass that was overridden from the superClass, then this method will not replace the method of the superClass.

Note: Portable Object Compiler only.



subclass:

+ subclass :(STR) name

Method to dynamically subclass a class. Returns a new class object, registered under the name name, as subclass of self. Methods like findClass: will also return this new class.

Note: Portable Object Compiler only.



inheritsFrom:

+ inheritsFrom : aClass



new

+ new

Factory method to create and return a new instance of the class. The default implementation clears (zeroes) the memory for instance variables and initializes the isa pointer.

On systems that allow to recover from a failed memory allocation call, new might raise an exception that can be handled with ifOutOfMemory:. The default handler for this exception aborts the process.



copy

- copy

Should return a copy of the object. The difference with deepCopy is, that this copy might share pointers etc. with the receiver of the message. By default, copy just makes a byte copy of the memory for instance variables.



deepCopy

- deepCopy

Should return a deep copy of the object. Usually this means a copy that doesn't share objects with the original object and that can be free'ed independently. By default, deepCopy just makes a byte copy of the memory for instance variables.



free

- free

Frees the memory for this instance, and returns nil.



self

- self

Method that does nothing, except for returning self.



yourself

- yourself

Method that does nothing, except for returning self.



class

- class

Returns the class object for the receiver's class.



superclass

- superclass

Returns the supeclass object for the receiver's class.



class

+ class

Traditionally, the class of a class does NOT return the metaclass, but rather self (that, it, the class itself).



superclass

+ superclass

Traditionally, the class of a class does NOT return the metaclass, but rather self (that, it, the class itself).

Note: This method is less widely implemented (by different compilers) than the name might make you suspect it is.



name

- (STR) name

Returns the name of the object; implemented by default to return the name of the object's class.



name

+ (STR) name

Returns the name of the class.



findClass:

- findClass :(STR) aClassName

Returns the id of aClassName, if that class has been linked in this executable image, else nil.



selOfSTR:

- (SEL) selOfSTR :(STR) aSelName

Returns the selector of the string aSelName. Raises an exception if not found.



idOfSTR:

- idOfSTR :(STR) aClassName

Returns the id of the class named aClassName. Differs from findClass: in that an OC_CLASSNOTFOUND exception will be raised if aClassName is not found



hash

- (unsigned) hash

Returns a small integer value derived from the object, that should be equal for two objects for which isEqual: returns YES. By default, returns the pointer address of the object as an unsigned integer.



isEqual:

- (BOOL) isEqual : anObject

Should return YES if the receiver is equal to anObject. By default, compares the pointer addresses of the two objects.



idEqual:

- idEqual : anObject

This method is implemented in terms of isEqual:. If isEqual: is properly implemented, then this method returns the Object idTrue or the Object idFalse if the receiver is respectively equal to, or not equal to, anObject.

This can be used in conjunction with such Block methods as ifTrue: or whileTrue: :

[[myObject idEqual:anObject] ifTrue:{[clones add:myObject];}];


isEqual:

+ (BOOL) isEqual : anObject

Tests whether two class objects are the same.



isSame:

- (BOOL) isSame : anObject

Returns YES if the pointer addresses of the two objects are equal.



notEqual:

- (BOOL) notEqual : anObject

Whether isEqual: returns NO.



notSame:

- (BOOL) notSame : anObject

Whether isSame: returns NO.



compare:

- (int) compare : anObject

Should return an integer which is less than, equal to, or greater than zero, if the receiver is less than, equal to, or greater than anObject. The return value is called the method's comparison value.



respondsTo:

- (BOOL) respondsTo :(SEL) aSelector

Test whether the class implements a certain method. Returns YES if the class itself, or one of its superclasses, implements the method, otherwise NO. The method does not generate an error if the class does not implement the method.



isMemberOf:

- (BOOL) isMemberOf : aClass

Returns YES if the receiver is an instance of aClass, but NO if it's an instance of some subclass of aClass.



isKindOf:

- (BOOL) isKindOf : aClass

Returns YES if the receiver is an instance of aClass or an instance from some subclass of aClass.

Note: For portability, this method always needs to be used as follows:

[ foo isKindOf:(id) [Classname class] ];
The reason is that some compilers do not allow class names as expressions, so the class must be obtained by sending a class message. In addition, some compilers have a isKindOf: method that takes an id argument, but the return value of self or class can be SHR for those compilers. Therefore, it's necessary to cast the return value to id (to avoid compiler warnings).



isTrue

- (BOOL) isTrue

Returns YES for any object that is not the static object idFalse. Returns YES for idTrue.

Could be implemented by other classes, e.g. by Integer.



isFalse

- (BOOL) isFalse

Returns YES if the receiver is the static object idFalse.

Could be implemented by other classes, e.g. by Integer.



ifTrue:

- ifTrue : aBlock

Evaluate aBlock if the receiver isTrue. Otherwise return nil.

See also: Block



ifTrue:ifFalse:

- ifTrue : trueBlock ifFalse : falseBlock

Evaluate trueBlock if the receiver isTrue. Otherwise, evaluates the falseBlock.



ifFalse:

- ifFalse : aBlock

Evaluate aBlock if the receiver isFalse. Otherwise return nil.



ifFalse:ifTrue:

- ifFalse : falseBlock ifTrue : trueBlock

Evaluate falseBlock if the receiver is the idFalse object. Otherwise, evaluates the trueBlock.



subclassResponsibility:

- subclassResponsibility :(SEL) aSelector

Used in classes to indicate that the functionality is assumed to be implemented by a subclass. If the subclass does not implement the method, then this implementation is inherited. It generates an error message.



subclassResponsibility

- subclassResponsibility

For Stepstone compatibility.



shouldNotImplement:from:

- shouldNotImplement :(SEL) aSelector from : superClass

Opposite of subclassResponsibility:. This message should be send when a subclass in NOT supposed to implement some method.



notImplemented:

- notImplemented :(SEL) aSelector

Method to use for stub implementations. When designing the interface of the class, this method can be temporarily used, until the method is really implemented.



doesNotRecognize:

- doesNotRecognize :(SEL) aSelector

Sent by the runtime when the class does not implement some selector.



doesNotUnderstand:

- doesNotUnderstand :(SEL) aSelector

For compatibility with Smalltalk. Implemented in terms of doesNotRecognize:.



error:

- error :(STR) format,...

Generate an error message. Takes a format string in the style of the C library function printf, with a variable number of arguments.



methodFor:

- (IMP) methodFor :(SEL) aSelector

Returns a function implementation pointer for aSelector. Returns a pointer to an error handling function if the object does not respond to aSelector.

Use of this method is not encouraged, because by using the resulting function pointer, one is bypassing (the benefits of) dynamic binding.



instanceMethodFor:

+ (IMP) instanceMethodFor :(SEL) aSelector

Returns a function implementation pointer for aSelector. Returns a pointer to an error handling function if the object does not respond to aSelector.

Use of this method is not encouraged, because by using the resulting function pointer, one is bypassing (the benefits of) dynamic binding.



perform:

- perform :(SEL) aSelector

Returns the value that would result when sending aSelector to the receiver.



perform:with:

- perform :(SEL) aSelector with : anObject

Returns the value that would result when sending aSelector to the receiver with a single argument anObject. The following are equivalent :

[aReceiver perform:@selector(do:) with:anObject];
and

[aReceiver do:anObject];


perform:with:with:

- perform :(SEL) aSelector with : anObject with : otherObject

Returns the value that would result when sending aSelector to the receiver with arguments anObject and otherObject.



perform:with:with:with:

- perform :(SEL) aSelector with : anObject with : otherObject with : thirdObj

Returns the value that would result when sending aSelector to the receiver with arguments anObject and otherObject.



print

- print

Prints the object to the stdout and returns self. Implemented as,

return [self printToFile:stdout]; 


print

+ print

Prints the name of the class to the stdout and returns self.



printLine

- printLine

Prints the object (in the sense of print) and then a newline.



show

- show

Displays the object on the stderr, by using Filer code, and returns self. Because it is implemented in terms of Filer code, this method is completely unrelated to the print method, although that the goal in both cases is to print a symbolic representation of the object.

This method is extremely useful for debugging. The compiler automatically implements Filer methods, so this method dumps instance variables of the object in a symbolic format, without the programmer having to implement debug/printing routines.

Method for Stepstone compatibility. Used in Producer code.



printToFile:

- printToFile :(FILE *) aFile

Should print the contents of the object to aFile. Should return the receiver. By default, the method prints nothing. This is the method to override in subclasses to make print etc. work.



printOn:

- printOn :(IOD) anIOD

For compatibility with the Stepstone runtime. Invokes printToFile: and returns the receiver.



printOn:

- printOn :(FILE *) anIOD

Invokes printToFile: and returns the receiver.



objcrtRevision

+ (STR) objcrtRevision

Returns the version string of the runtime being used.



readFrom:

+ readFrom :(STR) aFileName

Activates the object stored in the file aFileName. The object will in all respects be functional, as it was before being stored. Works by indirectly calling fileIn(). The class AsciiFiler must be linked into the application for this method to work.

This message can be sent to any factory object without regard of the class of the object being read in. In other words, if file foo contains a saved instance of a OrdCltn, then

id myCollection = [Object readFrom:"foo"];
will work, ie. the receiver doesn't need to be OrdCltn. Returns nil on failure.



storeOn:

- (BOOL) storeOn :(STR) aFileName

Stores the receiver to a file named aFileName, in a format such that the object can then be activated later, using the readFrom: method. Works by indirectly calling the function storeOn(). The class AsciiFiler must be linked into the application for this method to work



fileOutOn:

- fileOutOn : aFiler

Writes the receiver on aFiler. This is the method that a subclass will override to do it own processing, if the default implementation, which automatically writes out all instance variables of type id, does not suffice.

This method will be invoked twice by the Filer class, during archiving.



fileInFrom:

+ fileInFrom : aFiler

Creates a new instance of the class, files in the instance from aFiler (by sending the new object a fileInFrom:) message, and returns the new object.



fileInFrom:

- fileInFrom : aFiler

Reads the receiver from aFiler. The default implementation automatically reads in instance variables of type id. This method must be overridden to match fileOutFor:, if that method was implemented by the subclass.

One should realize that, at the time this method is invoked, not all objects are guarantueed to be in a usable state. This is only true once the filer starts sending awakeFrom: messages.



awake

- awake

This message is sent to every object when it is filed in, after all the objects it references are in a usable state. The default implementation simply returns self.



awakeFrom:

- awakeFrom : aFiler

Allows the receiver to do some cleanup work after an object has been filed in. It is a generalization of the old -awake method. The difference is that this method passes aFiler as an argument. The default implementation is to send the awake message.