• 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: Michael Latta <email@hidden>
  • Date: Wed, 7 Jan 2004 20:08:11 -0800

The short answer is: "Smalltalk had that 30 years ago, but C won the war."

There is a longer answer if you control all the classes involved: "Do not use class methods." Use factory or singleton patterns. There is only one way to obtain class Asub when the code thinks it is Asuper. That is by asking an instance for it's class, or obtaining the class object from some data structure. In the case of asking an instance, just make it an instance method. In the case of accessing the class object from some data structure, access a factory instance instead. It can act as a proxy for the class, but override the implementation of any methods it likes. Since you are invoking the method on what the run-time thinks is an instance rather than a static reference, see part 1 of this answer.

Michael



If you need inheritance properties in class scope, do it using a class
accessor on the static variable, ie:

in .h file:

+ (int)myClassVariable;

in .m file:

static int myClassVariable = 0;

+ (int)myClassVariable {return myClassVariable;}

But this is the whole problem. If I then subclass this class and wish
myClassVariable to hold something different in the subclass but still
work with the inherited accessor / other methods, it won't. The
superclass's meClassVariable is used instead :(

Robert

---
GnuPG public key:
http://www.Far-Blue.co.uk

[demime 0.98b removed an attachment of type application/pgp-signature which had a name of PGP.sig]
_______________________________________________
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.
_______________________________________________
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>)
 >Re: class variables and class methods (From: Glenn Andreas <email@hidden>)
 >Re: class variables and class methods (From: Robert Goldsmith <email@hidden>)
 >Re: class variables and class methods (From: lbland <email@hidden>)
 >Re: class variables and class methods (From: Robert Goldsmith <email@hidden>)

  • Prev by Date: waveform question
  • Next by Date: Edit : select All - problem in cocoa App
  • Previous by thread: Re: class variables and class methods
  • Next by thread: Re: class variables and class methods
  • Index(es):
    • Date
    • Thread