Re: difference between a method and function?
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.