Re(2): Obj-C, class methods and instance methods
Re(2): Obj-C, class methods and instance methods
- Subject: Re(2): Obj-C, class methods and instance methods
- From: Jens Bauer <email@hidden>
- Date: Sun, 19 May 2002 22:46:54 +0200
Hi Chris,
On Sun, 19 May, 2002, Chris Hanson <email@hidden> wrote:
>
At 1:12 PM -0400 5/19/02, Sanj W. wrote:
>
>Im trying to understand the difference between class methods and instance
>
>methods in Obj-C. I thought that class methods are similar to static methods
>
>in Java, where one could call the method without instantiating an class.
>
>
Semantics time: You don't call methods, the runtime invokes methods
>
when you send messages. This distinction is subtle but very, very
>
important to understanding the gestalt of real object-oriented
>
programming. (I wish people here would make it more often, it helps
>
to keep things clear.)
>
>
So a class method is invoked when you send a message to a class.
>
e.g. in the message expression [NSString stringWithString:@"foo"],
>
you're sending the stringWithString: message to NSString, which is a
>
class. The runtime will invoke NSString's stringWithString: class
>
method to handle this message.
Yep. My picture of this is instead of...
(sender) --message--> (receiver)
... you get ...
(sender) --message--> (send) --message--> (receiver)
Whereas (...) is a "function".
(send) can fail, if the object doesn't have the receiving method, and you
might be able to recover from it.
If the top model was used, you'd get a crash if the receiving method
weren't present.
So (send) is the "phone company", and the (sender) and (receiver) would
each be a customer. ;)
Uhm, and Interface Builder is the cable guy, who's connecting the phones
to the phone company, and he might be able to change the sender/receiver
after compiling has been done.
(what an obscure explanation!)
Love,
Jens
--
Jens Bauer, Faster Software.
-Let's make the World better, shall we ?
_______________________________________________
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.