Re: Assessor Syntax: Why use (id with protocol) vs (class name *)?
Re: Assessor Syntax: Why use (id with protocol) vs (class name *)?
- Subject: Re: Assessor Syntax: Why use (id with protocol) vs (class name *)?
- From: Amourine Tech <email@hidden>
- Date: Fri, 04 Nov 2011 11:51:29 -0700
I can see the benefit of sharing a method declaration across implementations that don't share a common base code. That is, having more-autonomous method implementations of the same (shared) method declarations.
For example: [myFunction getFood]; vs [yourFunction getFood];
Using a metaphor…
1) myFunction's getFood() hunts wild game; returns 'food'. 2) yourFunction's getFood() goes to a neighborhood store & buys it.
…without having to override its superclass to change the implementation.
Added benefit: … via protocols an instantiated object can incorporate assorted grocery-bag of methods that could be implemented in other ways in other objects.
I'm assuming there's no performance difference between the streamlined object-hierarchy approach & the use of protocols.
Ric.
On Nov 3, 2011, at 5:22 PM, Jens Alfke wrote: On Nov 3, 2011, at 4:57 PM, Amourine Tech wrote: Is there an advantage to using id <protocol>?
It’s the same reason why protocols (and Java interfaces, which were inspired by them) exist: to allow multiple implementations that don’t have to share a common base class. If the method were declared as returning ViewOrdersAccessor*, then (a) it couldn’t be overridden to return some other implementation of ViewOrdersService, and (b) the implementation couldn’t be changed to return some other implementation without altering the interface, which might break clients.
—Jens
|
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden