patrick
patrick

Reputation: 9742

how can I automatically get the same methods in multiple classes with different inheritance?

I have a singleton class that I want accessible via a helper method on multiple classes...

One of my classes inherits from CCLayer:

@interface Game : CCLayer

the other NSObject:

@interface Question : NSObject

... So my thought was to create a class:

#import "Storeizer.h"

@implementation Storeizer

-(StorageMechanism*)store {
    return [StorageMechanism sharedStorageMechanism];
}

@end

And have both Game and Question classes inherit from Storeizer so that they can automatically have a self.store convenience method.... However, this is a problem since my other classes already inherit from different objects (CCLayer and NSObject). So, I am a little confused how to proceed, and am wondering if this convenience method is more trouble than it's worth. I just come from a world where I hate to have redundant code, and having multiple classes calling [StorageMechanism sharedStorageMechanism] feels a little unfriendly on the eyes (to me at least).

So, how can I solve this problem?

Upvotes: 0

Views: 83

Answers (1)

J2theC
J2theC

Reputation: 4452

Add a category to NSObject, and import the header of the category where you are using these methods.

Upvotes: 1

Related Questions