Q's about Obj-C
Q's about Obj-C
- Subject: Q's about Obj-C
- From: Joe Chan <email@hidden>
- Date: Mon, 15 Oct 2001 11:23:20 -0400
I'm new to Cocoa/Obj-C (from the PP/C++ world), and I have some
questions about the language itself:
1. When I'm defining the init method for my derived class, I
read that I need to deal with [super init] returns nil. It's not
entirely clear to me when that happens, who should dealloc the
memory of the object? It doesn't seem right to me for the
derived classes to deal with it, because if every derived class
does it, there will be two many dealloc's chained together. The
only place it seems sensible to dealloc is from the actual init
method of the class that decides to return nil for some reason.
Is that indeed the case?
2. It's not clear to me when I need to declare a method in the
header file. From my reading of the Vermont Recipes at Stepwise,
the language does not require me to declare methods in the
header file if I override the super's method, or implement a
delegate method. Does that mean the only time I need to declare
a method in the header is when I introduce a new method to the
class?
3. About the fact that all method of the same name needs to
receive the same argument and return types. I'm a little
confused by that. Does that apply only to the case of overriding
existing method? Say if I have two classes A and B that belongs
to different class hierarchies, and they both declare method foo:
@interface A : ParentOfA
-(int)foo: (float)arg;
@end
@interface B : ParentOfB
-(void)foo: (int)arg;
@end
Is this illegal? If so, how does one go about ensuring unique
method names within a potentially large class hierarchy?
4. What makes a class an abstract class? In C++, that's caused
by a pure virtual function, but there doesn't seem to an
equivalent in Obj-C.
Thanks
-----------
Joe Chan
email@hidden
http://www.firstian.com