• 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: Why use protocols?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NEWBIE: Why use protocols?


  • Subject: Re: NEWBIE: Why use protocols?
  • From: Bob Ippolito <email@hidden>
  • Date: Wed, 18 May 2005 16:06:23 -0400


On May 18, 2005, at 3:59 PM, Ondra Cada wrote:

On 18.5.2005, at 21:50, Bob Ippolito wrote:


It is never *needed* to use protocols in the same way as you could define every pointer in C as a void*, it's merely another convenience of the language that assists you the programmer in getting your job right. If an object is supposed to subscribe to a protocol, then the type checker can check that you haven't bungled your code for you :)


Ammm... there's a bit more than this. Namely, a formal protocol (unlike an informal one!) is a runtime object, which (among other) can be enquired for signatures of its messages.


Agreeably that is in fact needed *quite* seldom, but sometimes it just might (like with the DO I've mentioned before).


You can ask ANY object that conforms to NSObject what the signatures of its messages are!


+[NSObject instanceMethodSignatureForSelector:]
-[NSObject methodSignatureForSelector:]


Does not help if the object happens to be at the other side of DO and the network round-trip is costly. That's what protocols are used for in DO, to remove the need for costly round-trips.

There are plenty of other ways it could be done, efficiently even.

Does not help either if there's no class (and thus also no instance) implementing an appropriate method -- that's the case of my dynamic frameworks. They implement methods through - formwardInvocation:, but first they need to provide an appropriate method signature, and that's the problem.

If they implemented these methods as well as the forwardInvocation:, then it could still be done.


Anyway, DO is one of the special cases I mentioned where it still makes sense to use protocols, because the implementation basically requires them.

-bob

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >NEWBIE: Why use protocols? (From: "Ben D. Jones" <email@hidden>)
 >Re: NEWBIE: Why use protocols? (From: Cameron Hayne <email@hidden>)
 >Re: NEWBIE: Why use protocols? (From: Daniel Jalkut <email@hidden>)
 >Re: NEWBIE: Why use protocols? (From: Ondra Cada <email@hidden>)
 >Re: NEWBIE: Why use protocols? (From: "Ben D. Jones" <email@hidden>)
 >Re: NEWBIE: Why use protocols? (From: Thomas Davie <email@hidden>)
 >Re: NEWBIE: Why use protocols? (From: Ondra Cada <email@hidden>)
 >Re: NEWBIE: Why use protocols? (From: Bob Ippolito <email@hidden>)
 >Re: NEWBIE: Why use protocols? (From: Ondra Cada <email@hidden>)

  • Prev by Date: Beware abs function in Core Data
  • Next by Date: Re: Moral to call [self windowDidLoad] ?
  • Previous by thread: Re: NEWBIE: Why use protocols?
  • Next by thread: Re: NEWBIE: Why use protocols?
  • Index(es):
    • Date
    • Thread