• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Q's about Obj-C
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Q's about Obj-C
      • From: Normand Rivard <email@hidden>
References: 
 >Re: Q's about Obj-C (From: Joe Chan <email@hidden>)

  • Prev by Date: Re: Q's about Obj-C
  • Next by Date: Re: Displaying an alert box
  • Previous by thread: Re: Q's about Obj-C
  • Next by thread: Re: Q's about Obj-C
  • Index(es):
    • Date
    • Thread