Re: Several questions
Re: Several questions
- Subject: Re: Several questions
- From: "David P. Henderson" <email@hidden>
- Date: Fri, 6 Jul 2001 20:03:07 -0400
On Friday, July 6, 2001, at 03:28 , jgo wrote:
>
Well, I know what a class is, and I know what an instance is,
>
but what is an "instance method" as opposed to a "class method"?
>
I never considered the possibility that a method would be
>
instantiated, as contrasted with data members/instance variables.
>
In Objective-C, a class is an object. The class object is the prototype
for all instances of the class, but it has no instance variables and can
not perform instance methods. A class can contain methods specifically
for the class; think of class methods as factories for turning out
specifically built instances of the class. For example, [MyObject alloc]
returns an instance of MyObject with data members initialized to nil,
null, zero, etc... dependent on the type of the variable. If you want an
instance of MyObject ready for use without initing it, you should
provide class methods to do so. For example, [NSString
stringWithString:@"My string"] returns an instance of NSString with a
value of "My string".
So an instance method isn't an instaniated method; rather, it is a
method which only instances of a class can perform.
Dave
--
Chaos Assembly Werks
"The Trend over the last 20 years or so has been to design computer
languages that enforce a state of paranoia. You're expected to program
every module as if it were in a state of siege In Perl culture, by
contrast, you're expected to stay out of someone's home because you
weren't invited in, not because there are bars on the windows."
from Programming Perl