• 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: Instance methods VS. Class methods
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Instance methods VS. Class methods


  • Subject: Re: Instance methods VS. Class methods
  • From: Jeff LaMarche <email@hidden>
  • Date: Sat, 24 Nov 2001 09:13:12 -0800

Well, class methods are ones that you can use regardless of whether you've instantiated any objects of that class or not. The most common use of class objects is a "generator" class, such as [NSImage imageWithContentsOfFile], which returns an NSImage object. You use these generator classes in lieu of the alloc/init calls. Class methods are also used much the same way that a public static method is in Java. Class methods cannot access any instance variables (just like static methods) and must be self-contained. This makes them well-suited to utility methods or methods related to a class that other objects might want to use.

Instance methods are just like methods in Java and member functions in C++ - you have full access ot the instance variables, but they only operate on the instance they belong to and there must be an instance of the object in order to access them.

I have a feeling someone else will come along with a more elegant explanation, but that should give you a basic understanding of the difference.

Jeff


On Friday, November 23, 2001, at 08:19 PM, Matt Ronge wrote:

Hi,

I've read through Apple's docs, read through Learning Cocoa, and I have
searched all over the web. Yet none of them have shed light on the
difference between instance methods and class methods?

Can someone give examples of why you would use one over the other? Is there
something comparable in C++ to them? Is one of them just a private method
identifer for use internally by the class?

Sorry for the newbie question,

Forward thanks for any help,
--
Matt Ronge

President
Monkeybread Software
http://www.monkeybreadsoftware.com
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev


References: 
 >Instance methods VS. Class methods (From: Matt Ronge <email@hidden>)

  • Prev by Date: Handling keydown events
  • Next by Date: Re: Adding a port to the run loop of a different thread.
  • Previous by thread: Re: Instance methods VS. Class methods
  • Next by thread: DOcument Icons
  • Index(es):
    • Date
    • Thread