• 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: Daniel Jalkut <email@hidden>
  • Date: Wed, 18 May 2005 10:05:53 -0700

Also keep in mind that a protocol allows the method declarations to stay in one place (the protocol definition) without requiring them to be redundantly defined in each class that conforms to the protocol.

Consider your idea that you might as well just put the declarations in the object. You could do that, but then if the protocol changes in any way, you run the risk of having objects that are no longer conforming but do not trigger any errors on build.

Daniel

On May 18, 2005, at 8:25 AM, Cameron Hayne wrote:

On 18-May-05, at 11:11 AM, Ben D. Jones wrote:


I don't get why or when the use of a protocol is a must for clarity or function.


Protocols are useful when you have more than one class that you want to use interchangeably in some circumstances. If you don't care about what type of object is being handled as long as it understands (implements) the "UpDown" protocol, then you can declare a parameter as:
id <UpDown>
instead of restricting it to a specific class.
In this way, protocols are useful in circumstances where multiple inheritance might be used in C++


--
Cameron Hayne
email@hidden


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


This email sent to email@hidden


_______________________________________________ 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>)

  • Prev by Date: Re: Loading already scaled JPEGs
  • Next by Date: Re: Why use protocols?
  • Previous by thread: Re: NEWBIE: Why use protocols?
  • Next by thread: Re: NEWBIE: Why use protocols?
  • Index(es):
    • Date
    • Thread