Drawbacks with using Class Methods in Objective C.

Posted by RickiG on Stack Overflow See other posts from Stack Overflow or by RickiG
Published on 2010-04-22T18:49:13Z Indexed on 2010/04/22 23:43 UTC
Read the original article Hit count: 279

Filed under:
|

Hi

I was wondering if there are any memory/performance drawbacks, or just drawbacks in general, with using Class Methods like:

+ (void)myClassMethod:(NSString *)param {
// much to be done...
}

or

+ (NSArray*)myClassMethod:(NSString *)param {
// much to be done...
    return [NSArray autorelease];
}

It is convenient placing a lot of functionality in Class Methods, especially in an environment where I have to deal with memory management(iPhone), but there is usually a catch when something is convenient?

An example could be a thought up Web Service that consisted of a lot of classes with very simple functionality. i.e.

TomorrowsXMLResults;
TodaysXMLResults; 
YesterdaysXMLResults;
MondaysXMLResults;
TuesdaysXMLResults;
.
.
.
n

I collect a ton of these in my Web Service Class and just instantiate the web service class and let methods on this class call Class Methods on the 'Results' Classes. The classes are simple but they handle large amount of Xml, instantiate lots of objects etc.

I guess I am asking if Class Methods lives or are treated different on the stack and in memory than messages to instantiated objects?

Or are they just instantiated and pulled down again behind the scenes and thus, just a way of saving a few lines of code?

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about class-method