Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
December 10, 2018, 03:21:19 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register Chat  
Pages: [1]   Go Down
  Print  
Author Topic: Informal Protocols vs. Categories  (Read 6291 times)
alamba78
Newbie
*
Posts: 6


« on: July 26, 2009, 08:13:37 PM »

On Pg. 234, there is an example of an informal protocol (NSComparisonMethods).  But, it is defined as a Category without the @protocol section name.  So, what exactly makes this a protocol and not just a category?  Or is any list of methods that are grouped together and shared among classes called a protocol, regardless of whether the @protocol is used or not???

Thanks!
Logged
SiriusA
Newbie
*
Posts: 22


« Reply #1 on: August 13, 2009, 07:07:14 PM »

I registered the same confusion when I read that section.
Logged
skochan
Administrator
Hero Member
*****
Posts: 3114



« Reply #2 on: August 13, 2009, 10:10:17 PM »

It's called an informal protocol because we don't define it with the @protocol directive but as a category.  As noted in the text, it's just a way to group a set of methods logically together.  Someone can then implement one or more of those methods from that group.  Informal protocols were created because before the @optional directive was added to the language for specifying optional methods in a protocol, all the listed methods in the protocol definition had to be implemented.  As you know with a category, you don't have to implement all the methods listed in a category definition.

Hope this helps.

Cheers,

Steve
Logged
SiriusA
Newbie
*
Posts: 22


« Reply #3 on: August 14, 2009, 12:40:30 PM »

thank you so much for your speedy reply!

yes, that really clarifies it for me. I suspect that you've said the same thing in the text but having it digested and condensed into such a definitive statement made all the difference. I'll continue to browse the forums and read elsewhere on the web but I'm continuing to have problems (as revealed by errors thrown when doing the exercises) as to the proper syntax -- but this may have just cracked the code for me. (Sometimes I expect the "rules" to be more complex / convoluted / involved then they really are.)
Logged
alamba78
Newbie
*
Posts: 6


« Reply #4 on: August 21, 2009, 09:32:05 PM »

Sweet!  Thanks Steve.  I'm sure there will be more questions to come along the way.  Smiley


Amit
Logged
MarkReid
Full Member
***
Posts: 173


« Reply #5 on: October 13, 2009, 09:55:22 AM »

I sort of understand this but am still not sure why an informal protocol is not just called a category. Does it simply have to do with how Obj-C developed? Protocols came first and then informal protocols, called such because you don't neccessarrily want to implement any of them, categories are methods you "will" use in the same class but again maybe not all of them?

Can someone tell me what I'm missing? Thanks
Logged
skochan
Administrator
Hero Member
*****
Posts: 3114



« Reply #6 on: October 13, 2009, 11:52:44 AM »

A category is usually an extension of a specific class, and is usually used to extend the functionality of that class.  A protocol, on the other hand, is a list of methods for subclasses to implement.   As noted, an informal protocol is really just a category, but was used before the @optional directive permitted methods to be listed for optional implementation.  So, it's a matter of semantics.  Using the term "protocol" implies a list of methods for someone else to implement.   Category does not imply that usage.

Cheers,

Steve Kochan
Logged
MarkReid
Full Member
***
Posts: 173


« Reply #7 on: October 13, 2009, 12:04:52 PM »

Thanks Steve. That's just what I needed to know.
Logged
hame
Newbie
*
Posts: 1

coaw@outlook.com hame hame
« Reply #8 on: January 19, 2015, 11:42:06 AM »

So am I to take it from lack of posts that everyone is perfectly happy with all the above categories, and they neither want to add or remove any of them?
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents ゥ 2009 classroomM.com. All rights reserved.