Re: Q's about Obj-C
Re: Q's about Obj-C
- Subject: Re: Q's about Obj-C
- From: Ondra Cada <email@hidden>
- Date: Mon, 15 Oct 2001 18:36:50 +0100
Bradley,
>
>>>>> Smith, Bradley (SB) wrote at Mon, 15 Oct 2001 16:29:44 +0100:
[polymorphism outside of class or protocol hierarchy]
SB> 3. Dunno, but be interested to find out
See my previous message.
[abstract classes]
SB> 4. You've opened a can of worms here :-) AFAIK you can't have an abstract
SB> class in Obj-C. Someone will probably go to great lengths to tell you why
SB> and attempt to make you feel stupid for even wanting to do it.
Well, would you feel stupid if I'll try to explain that once more?
(i) You can't have compiler to enforce abstract classes since we have a
dynamic language:
Class c=runtime_known_value?[NonAbstractClass class]:[AbstractClass class];
id o=[c new]; // and what now?!?
(ii) You can have runtime-abstract class if you really want to (though I
haven't *EVER* seen a situation when this would be desirable!!!):
@implementation AbstractClass
-init {
[self autorelease];
NSLog(@"Attempt to create an instance of anstract class %@",[self class]);
return nil;
}
...
@end
(iii) Instead of the slightly pathological situation of (ii), you can --
thanks to the fexibility of the alloc/init system -- implement class clusters
instead:
@implementation AbstractClass
-init {
[self autorelease];
return [[SomeReasonableConcreteSubclass alloc] init];
}
...
@end
---
Ondra Cada
OCSoftware: email@hidden
http://www.ocs.cz
2K Development: email@hidden
http://www.2kdevelopment.cz
private email@hidden
http://www.ocs.cz/oc