• 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: Objective-C Question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Objective-C Question


  • Subject: Re: Objective-C Question
  • From: Graham Cox <email@hidden>
  • Date: Tue, 12 Mar 2013 19:44:02 +1100

On 12/03/2013, at 6:31 PM, Dave <email@hidden> 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 (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Objective-C Question
      • From: Dave <email@hidden>
References: 
 >Objective-C Question (From: Dave <email@hidden>)
 >Re: Objective-C Question (From: Mike Abdullah <email@hidden>)
 >Re: Objective-C Question (From: Dave <email@hidden>)
 >Re: Objective-C Question (From: John McCall <email@hidden>)
 >Re: Objective-C Question (From: Dave <email@hidden>)
 >Re: Objective-C Question (From: John McCall <email@hidden>)
 >Re: Objective-C Question (From: Dave <email@hidden>)

  • Prev by Date: Another Gnarly Objective-C Question!
  • Next by Date: Re: Another Gnarly Objective-C Question!
  • Previous by thread: Re: Objective-C Question
  • Next by thread: Re: Objective-C Question
  • Index(es):
    • Date
    • Thread