• 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 14:55:27 -0400

On May 18, 2005, at 2:32 PM, Ben D. Jones wrote:

The reason I ask is that I'm actually starting on a very large project (my first big project) in Cocoa. Having done large projects in C I'm not a newbie to programming, just Cocoa. So in what cases (example of use) would it be needed or proper to use protocols?

In general, you never need nor want formal protocols. They're effectively worthless and generally cause more problems than they (attempt to) solve. It's very much a B&D[1] language feature, but there's no benefit to using them with the runtime's extremely weak type system and the fact that there's no runtime or framework support for protocol adaptation... There are also some weird corner cases with protocols (Jaguar's runtime crashes if you define a protocol in a MH_BUNDLE, the namespace for them is really weird so unexpected things can happen if you have a version mismatch between protocols, etc.).


Don't bother with them, unless you're dealing with some ancient API that wants you to create or implement them (Distributed Objects, NSCoder, etc.). As mentioned, the "modern" way is to define informal protocols (categories on NSObject) when necessary, implement the subsets of the informal protocols you need for the class, and make runtime checks to see if the objects implement the required methods (- [NSObject respondsToSelector:], etc.).

.. [1]: http://c2.com/cgi/wiki?BondageAndDisciplineLanguage

-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


  • Follow-Ups:
    • Re: NEWBIE: Why use protocols?
      • From: Ondra Cada <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>)

  • Prev by Date: Re: NEWBIE: Why use protocols?
  • Next by Date: Re: Spotlight Plugin Woes
  • Previous by thread: Re: NEWBIE: Why use protocols?
  • Next by thread: Re: NEWBIE: Why use protocols?
  • Index(es):
    • Date
    • Thread