• 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: class variables and class methods
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: class variables and class methods


  • Subject: Re: class variables and class methods
  • From: Shawn Erickson <email@hidden>
  • Date: Thu, 8 Jan 2004 09:27:30 -0800

On Jan 7, 2004, at 2:15 PM, Robert Goldsmith wrote:

Hi everyone :)

Sorry if this is a simple question but it has been driving me up the wall :(

Maybe I was wrong to expect this but I thought class methods and class variables would behave much like instance ones, but this does not seem to be the case. Let me outline the problem:

Starting simple, I have class A, which has an instance method (lookup) that refers to a static (so it won't inherit) class variable called lookupTable (which is a c style array). Every instance of class A uses the same lookup table. This works fine.

Now, I create a subclass of A called As and define a new static class variable in As with the same name, lookupTable. When I call lookup in an instance of As, I get back details from the lookupTable variable in A, not the one in As.

Is there any easy way to fix this?

So far, I have found the only way is to access lookupTable via an accessor method that must be repeated in every subclass of A. This is not very good as it means repeating the accessor when, really, it should just be inherited. On the other hand, at least the accessor is small and not prone to have bugs in it :) It just seems very messy and non oo :(

FYI

The concept of class variables and their addition to the Objective-C language are being pondered on the new Objective-C language list Apple recently created (http://www.lists.apple.com/mailman/listinfo/objc-language). Make sure to review the archives of that list if you are interested what has transpired already (archives can be accessed from the list's web-page).

Note several other items are being discussed on the list as well (unification of GNU and Apple runtimes, GC, namespaces, generics, literals, blocks, etc.).

-Shawn
_______________________________________________
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: 
 >class variables and class methods (From: Robert Goldsmith <email@hidden>)

  • Prev by Date: Re: Collection classes
  • Next by Date: Re: Thinking about shareware prices... (was a question about NSDate inside userDefaults)
  • Previous by thread: Re: class variables and class methods
  • Next by thread: Cd ejection detecting
  • Index(es):
    • Date
    • Thread