Re: Class Methods & Class Objects?
Re: Class Methods & Class Objects?
- Subject: Re: Class Methods & Class Objects?
- From: Rainer Brockerhoff <email@hidden>
- Date: Tue, 21 Aug 2001 13:40:10 -0300
>
Date: Mon, 20 Aug 2001 20:58:59 -0400
>
From: Brian Howard <email@hidden>
>
>
On Monday, August 20, 2001, at 08:18 PM, James Bredijk wrote:
>
>
> Hi,
>
> As a Cocoa newbie, I'm a little confused with "class methods" &
>
> "class objects". Could someone explain what these things do as apposed
>
> to instance methods & instance objects??
>
>
Let's test my education so far: "class methods" are sent directly to the
>
class in question, while instance methods are sent to instance objects.
>
Class objects are more or less nothing other than "factories" designed
>
to "stamp out" instances--the objects that do the actual work. There is
>
bound to be more to it than that; wiser heads will fill us in, no doubt.
You can also use class methods to return data relating to the class, or static data used internally by the class. For instance, when you call [NSUserDefaults standardUserDefaults], this returns a pointer to a default instance of the class - which is stored in a static variable internally in NSUserDefaults, and initialized on the first call.
There are other cases like [NSImage imageUnfilteredFileTypes] which returns an NSArray* of file types which can be opened by NSImage, so this isn't a "factory" method for getting NSImage's.
--
Rainer Brockerhoff <email@hidden>
Belo Horizonte, Brazil
"In the affairs of others even fools are wise
In their own business even sages err."
http://www.brockerhoff.net/ (updated July 2000)