• 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: Newbie Questions About Methods and Messages
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie Questions About Methods and Messages


  • Subject: Re: Newbie Questions About Methods and Messages
  • From: "John C. Randolph" <email@hidden>
  • Date: Fri, 9 Aug 2002 14:40:39 -0700

On Friday, August 9, 2002, at 01:45 PM, Brendon Bruns wrote:

Hello, this is my first time posting to this list so please excuse me if I
made any obvious errors in doing so.
I am a newbie to the world of Cocoa so please don't flame me for asking
simple questions.

Hey, that's what we're here for!

Anyway, to start off with, methods and messages both appear that they can
both return information to whomever send them. If they return nothing, they
return void. Am I correct so far?

Okay, let me try to clarify the difference between a method and a message. The Message is what you send to an object. The method is the code that the object executes in response to the message. In a nutshell, when I evaluate an expression like [someObject doSomething], I'm sending "doSomething" to "someObject", which then looks through its method tables for a method filed under "doSomething". If it finds such an entry, it runs that code.


Well, my main question is, what is the point, really, of having a method
returning data when a message could also do it?

Messages don't actually return anything. Messages are not code, they're a request to run code.

Another question, a class, when executed, creates an object instance of that
class. Correct?

It may help to think of a class as a "factory for objects". There's no such operation as "executing a class". You can send a class a message like +alloc to create a new instance.


Well, I believe there is a way to create objects without
using a class...or that is how I have interpreted it. Or, do you always
need to have a class declare an instance of itself to make an object, or can
it be done without the class?

Whenever you instantiate an object, you need to know the memory layout of the object you're creating. That layout is stored in a class, so in Obj-C it makes no sense to create an object "without a class."

-jcr

John C. Randolph <email@hidden> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
http://developer.apple.com/cocoa/index.html
_______________________________________________
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: 
 >Newbie Questions About Methods and Messages (From: Brendon Bruns <email@hidden>)

  • Prev by Date: Optimized Method for Ellipses in NSTableView?
  • Next by Date: Further GUI wrapper problems
  • Previous by thread: Newbie Questions About Methods and Messages
  • Next by thread: Re: Newbie Questions About Methods and Messages
  • Index(es):
    • Date
    • Thread