• 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: Obj-C, class methods and instance methods
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Obj-C, class methods and instance methods


  • Subject: Re: Obj-C, class methods and instance methods
  • From: Ondra Cada <email@hidden>
  • Date: Tue, 21 May 2002 21:53:34 +0200

On Tuesday, May 21, 2002, at 08:02 , email@hidden wrote:

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.

Chris Hanson wrote:
|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.)

Speaking as one of those people who consistently fail to make this distinction, I fail to do so because I see no distinction to make.

Well, that's not a shame. There's lot of people who did not grok dynamic object-oriented programming yet. You should learn though, instead of making a point of your not understanding.

"Calling" a chunk of code is simply transferring control to it, leaving a trail of breadcrumbs behind so you can find your way back.

Right. The keyword here is "simply transferring control to it".

"Invoking" a chunk of code is exactly the same thing.

Might be, but that's not the point. (You missed in the original post that *runtime* invokes the method, not the caller!)

The important point is that in a dynamic system like ObjC (or Smalltalk) is, you don't call nor invoke: you *send messages*. That is an *utterly* different thing.

When you send a message, you specify the message itself, its arguments if any, and its receiver. Noticed? We haven't mention any code at all -- and rightly at that.

The thing is that sending a message is highly abstract operation. *Unlike*
"invoking" or "calling" code, when sending a message, you don't determine what will happen: that depends on the receiver (that's, incidentally, the most important thing of OOP, and is called "encapsulation").

True is that normally the receiver (actually, the runtime using information from the receiver) selects some message and calls it. It is not necessary though: the receiver might take the message as is and send it to someone other. It can also translate the message to some quite different format and deliver it into a quite different environment -- that is the base of bridging. Or, it might decide to send the message through LAN: see, we've got Distributed Objects (almost) for free.
---
Ondra Hada
OCSoftware: email@hidden http://www.ocs.cz
2K Development: email@hidden http://www.2kdevelopment.cz
private email@hidden http://www.ocs.cz/oc
_______________________________________________
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.
References: 
 >Re: Obj-C, class methods and instance methods (From: email@hidden)

  • Prev by Date: Re: Newbie question: setting a NSNumber
  • Next by Date: Re: Frameworks in HOME/Library, why?
  • Previous by thread: Re: Obj-C, class methods and instance methods
  • Next by thread: Re: Obj-C, class methods and instance methods
  • Index(es):
    • Date
    • Thread