On 12/03/2013, at 6:31 PM, Dave <d...@looktowindward.com> wrote:

> I don't think you understand the difference between class methods and 
> instance methods.

Are you certain you do?


> Here is an example of what I mean:


Why not state you goals instead of give us a lump of incoherent code?

As far as I can see you don't need a series of subclasses here (unless there is 
something else going on you haven't told us about). If you just want some 
factory classes to return certain prefilled dictionaries, then just do that, 
and forget about trying to mangle the meaning of inheritance and do something 
overcomplicated.

All you need is:


@interface DictionaryFactory1 : NSObject

+ (NSDictionary*) dictionary;

@end

// repeat the above with additional class names as desired, e.g. 
DictionaryFactory2, DictionaryFactory3



+ (NSDictionary*)  dictionary
{
        // create the dictionary

        // set some preloaded data

        // return it
}


then your code just calls [DictionaryFactory1 dictionary], [DictionaryFactor2 
dictionary] etc.


what's so hard about that?

(n.b. it's NSDictionary, not MSDictionary, you may have the wrong OS in mind).



Even if Dictionary factory 2 inherits from Dictionary factory 1 for some reason 
that isn't clear from your post, it doesn't change this at all. You just 
override +dictionary and return what you want. There is no reason to call super 
at all.

If you want DF2 to add some further items to DF1's implementation, then call 
super and add the extra items to the dict:


@implementation DF2

+ (NSDictionary*) dictionary
{
        NSMutableDictionary* md = [[super dictionary] mutableCopy];

        // add extra items to md

        return [md autorelease];
}

--Graham


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to