RE: New Obj-C root class and forwarding
RE: New Obj-C root class and forwarding
- Subject: RE: New Obj-C root class and forwarding
- From: Jean-Daniel Dupas <email@hidden>
- Date: Tue, 18 Mar 2003 16:44:35 +0100
I can't directly help you, but if you want to know how NSObject or Object
works, you can find source code in the Opensource project GnuStep. Search on
the net
http://savannah.gnu.org/projects/gnustep/
You can browse the source on-line. There is most of the class that you can
found in the Apple version of the frameworks.
>
>
I'm writing some test classes for fairly academic reasons and I've run
>
into some questions. I'm playing with the class heirarchies and
>
restrictions of the inheritance mechanisms. The problems I've run into
>
stem around trying to create a new root class that inherits from a root
>
interface.
>
>
My goal was to create a new root class (i.e. that does not inherit from
>
NSObject (or Object for that matter)) that conforms loosely to some
>
interface that defines minimal abstract functionality and data. The
>
problem I get is that I get a run-time error regarding message forwarding:
>
>
objc: Shape: Does not recognize selector forward::
>
Abort trap
>
>
I believe I roughly understand the parent forwarding mechanism and the
>
error given would imply that that is one of potentially a handful of class
>
mechanisms that I'd need to implement to generate a new root class. Is
>
this true? At a minimum, this would imply that there are objective-C
>
run-time semantics that are being assumed by linking with the -lobj
>
library.
>
>
So, here's some code. Please remember that this is all just academic.
>
that said, we start with a root interface:
>
>
@interface Shape {
>
int x;
>
int y;
>
}
>
- (int)x;
>
- (int)y;
>
- (int)x: (int)aNumber;
>
- (int)y: (int)aNumber;
>
@end
>
>
And then we create a new root class that conforms to the Shape interface:
>
>
#import "Shape.h"
>
@interface Circle:Shape {
>
int radius;
>
}
>
+ (Circle *)x: (int)xValue y: (int)yValue radius: (int)aRadius;
>
- (int)radius;
>
- (int)radius: (int)aNumber;
>
@end
>
>
The Circle instantiator is presently as follows:
>
>
@implementation Circle
>
+ (Circle *)x: (int)xValue y: (int)yValue radius: (int)aRadius {
>
return self ;
>
}
>
.
>
.
>
.
>
@end
>
>
Finally, the driver test code:
>
>
#import "Circle.h"
>
main() {
>
int i;
>
Circle *shape[100];
>
for (i=0; i<100; i++) {
>
shape[i] = [Circle x: rand() y: rand() radius: rand()];
>
}
>
}
>
>
At a naive attempt to quell the error, I add a "forward" class method to
>
Circle that simply returns self. This quells the error about Circle not
>
responding to forward, and results in the error shown about about Shape
>
not responding to forward. If I add the same class method to Shape, the
>
error persists. If I subclass Shape off of NSObject, all is quelled.
>
>
1) Can anyone explain what is going on?
>
>
2) Can anyone explain how to get what I'm attempting to do to work without
>
subclassing off of a root class/interface?
>
>
Cheers!
>
>
Sean Morrison
>
U.S. Army Research Laboratory
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.