Re: OOP Clarification
Re: OOP Clarification
- Subject: Re: OOP Clarification
- From: jgo <email@hidden>
- Date: Wed, 2 Jan 2002 18:30:07 -0800
>
I've read about the difference between a class method and a instance method
>
before, but the difference has somehow become lost in my cobwebs. All I can
>
remember is the difference is subtle, but an important concept.
>
>
I can't find a good resource. Anyone know a good
>
reference/definition/example of the difference?
<
http://www.toastedmarshmallow.com> has some good words on the subject.
Here are mine:
Unlike C++, in Objective C certain methods are thought of as
belonging to the class itself, rather than to instantiated objects.
Commonly these are "factory methods" used to do instantiating
(but there can be class methods that are not factory methods).
They're designated by a plus sign at the beginning of their
declarations & definitions. When they are invoked (when you
"send a message to them", you might do it like this
[classname methodname]
NSButton * myButton = [[NSButton alloc] init];
Instance methods, are associated with already instantiated objects.
[instancename methodname]
[myButton setState:NSOnState];
John G. Otto, Eagle Scout, Knight, Cybernetic Praxeologist
Existence, Consciousness, Identity, Life, Liberty, Property, Privacy, Justice