• 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: difference between a method and function?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: difference between a method and function?


  • Subject: Re: difference between a method and function?
  • From: publiclook <email@hidden>
  • Date: Sun, 24 Aug 2003 17:56:03 -0400

On Sunday, August 24, 2003, at 04:37 PM, Ben Dougall wrote:

this might be a silly question but... i'm writing a bit of code that is contained pretty much within one object, apart from using the pre-written cocoa objects, and i'm wondering, from that point of view (from within one object), what's the difference between a method and a function? what are the advantages / disadvantages of either if any?

- (void)aMethod:(int) x
{
...
}

void aFunction(int x)
{
...
}


Do you ask a basically what is the point of polymorphism ?

A method in Objective-C is polymorphic and a function call is not which has many implications mostly applying to eventual subclasses if any.
A method can be easily overridden by a method in a category and a function can not.
A method has automatic access to an object's instance variables. A function can too but only if the function is implemented inside the @implementation @end block.
A method has two hidden arguments, self and _cmd. A function does not.
A function call is slightly faster than a sending a message that invokes a method.
Methods can be named to be more expressive about arguments than functions typically are.
_______________________________________________
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: 
 >difference between a method and function? (From: Ben Dougall <email@hidden>)

  • Prev by Date: difference between a method and function?
  • Next by Date: Re: difference between a method and function?
  • Previous by thread: difference between a method and function?
  • Next by thread: Re: difference between a method and function?
  • Index(es):
    • Date
    • Thread