• 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: Adding a method makes a class abstract?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Adding a method makes a class abstract?


  • Subject: Re: Adding a method makes a class abstract?
  • From: Thomas Lachand-Robert <email@hidden>
  • Date: Wed, 19 Mar 2003 13:10:34 +0100

Le lundi, 17 mars 2003, ` 12:27 Europe/Paris, Mark Patterson a icrit :

I'm going through the Hillegass book, and thought I'd try to change the
class used in one of the earlier exercises. So I subclassed NSNumber,
and when I ran it a line that worked with an instance of NSNumber gave
me an abstract object exception. Very strange from my Java / Delphi
point of view.

The code is:

#import <Foundation/Foundation.h>

@interface SimpleNumber: NSNumber {
}
- (NSString *)description;
@end

@implementation SimpleNumber
- (NSString *)description
{
return [[NSString alloc] initWithFormat:@"%d", [self intValue]];
}
@end


You can't easily subclass NSNumber, because it's a class cluster (search for these words in the list or at cocoa.mamasam.com); in particular, it's abstract hence the error. Anyway, there is no need here, since contrarily to Java/C++, Obj-c allows you to overwrite or define methods to any class. For instance:

@implementation NSNumber (additionalMethod)

-myAdditionalMethod (...) { }

@end

In general, try to refrain to subclass in Obj-C: most of the time, there is no need to. This is one of the reason Obj-C is much more productive that Java/C++.

Thomas Lachand-Robert
********************** email@hidden
<< Et le chemin est long du projet ` la chose. >> Molihre, Tartuffe.
_______________________________________________
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.

References: 
 >Adding a method makes a class abstract? (From: Mark Patterson <email@hidden>)

  • Prev by Date: Re: Beginner question with sheets
  • Next by Date: Re: From 256M to 768M and still paging a lot
  • Previous by thread: Re: Adding a method makes a class abstract?
  • Next by thread: Programatically opening a NSComboBox?
  • Index(es):
    • Date
    • Thread