Re: question about informal protocols

2009-11-22 Thread Henry McGilton (Boulevardier)

On Nov 20, 2009, at 12:22 PM, Jens Alfke wrote:

> 
> On Nov 20, 2009, at 12:09 PM, Michael de Haan wrote:
> 
>> Does the, in your opinion, "optional" addition pretty much replace 
>> categories as a whole, or is there still a role for them?
> 
> It replaces informal protocols. There are many other uses for categories, like
> 
> * Breaking a class implementation across several source files
> * Declaring private/internal class methods that a few other classes are 
> allowed to call
> * Declaring some of a class's methods in other headers (ones that only make 
> sense in the context of that other header)
> * Adding methods to a pre-existing framework class

Not to overlook the all-important AppKit and UIKit 'Additions' to their 
respective Foundation Frameworks . . . 

Cheers,
. . . . . . . .Henry


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: question about informal protocols

2009-11-20 Thread Michael de Haan

On Nov 20, 2009, at 12:19 PM, David Duncan wrote:

> On Nov 20, 2009, at 12:09 PM, Michael de Haan wrote:
> 
>> Did not see that it was deprecated, but will take your lead and convert them 
>> to that. Does the, in your opinion, "optional" addition pretty much replace 
>> categories as a whole, or is there still a role for them?
> 
> 
> The addition of @optional and @required to Protocols is meant to replace the 
> need for Informal Protocols. Categories are still very useful for adding 
> functionality to a class, as Protocols only allow you to create an interface, 
> not an implementation.
> --




Good...because the example makes much use of both categories and extensions...

:-)

Thanks David.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: question about informal protocols

2009-11-20 Thread Jens Alfke

On Nov 20, 2009, at 12:09 PM, Michael de Haan wrote:

> Does the, in your opinion, "optional" addition pretty much replace categories 
> as a whole, or is there still a role for them?

It replaces informal protocols. There are many other uses for categories, like

* Breaking a class implementation across several source files
* Declaring private/internal class methods that a few other classes are allowed 
to call
* Declaring some of a class's methods in other headers (ones that only make 
sense in the context of that other header)
* Adding methods to a pre-existing framework class

—Jens___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: question about informal protocols

2009-11-20 Thread Jean-Daniel Dupas

Le 20 nov. 2009 à 21:09, Michael de Haan a écrit :

>> 
>> 
>> The usual way is to NOT implements the NSObject category and test if the 
>> delegate implements the method using -respondsToSelector:
>> But this way works too if you don't want to have to test before sending your 
>> message.
>> 
>> Anyway, informal protocols are "deprecated" in favor of @protocol with 
>> @optional method.
>> 
>> 
>> -- Jean-Daniel
>> 
>> 
>> 
>> 
> 
> 
> Did not see that it was deprecated, but will take your lead and convert them 
> to that. Does the, in your opinion, "optional" addition pretty much replace 
> categories as a whole, or is there still a role for them?
> 


They are not formally deprecated (that's why I used quotes), but Apple replaced 
most if not all Cocoa informal protocols in 10.6 and there is no reason to use 
them anymore.

@optional replaces categories used as informal protocol, but this is not the 
only usage for categories. They are very useful if you want to add a method to 
an existing class.


-- Jean-Daniel




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: question about informal protocols

2009-11-20 Thread David Duncan
On Nov 20, 2009, at 12:09 PM, Michael de Haan wrote:

> Did not see that it was deprecated, but will take your lead and convert them 
> to that. Does the, in your opinion, "optional" addition pretty much replace 
> categories as a whole, or is there still a role for them?


The addition of @optional and @required to Protocols is meant to replace the 
need for Informal Protocols. Categories are still very useful for adding 
functionality to a class, as Protocols only allow you to create an interface, 
not an implementation.
--
David Duncan
Apple DTS Animation and Printing

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: question about informal protocols

2009-11-20 Thread Michael de Haan
> 
> 
> The usual way is to NOT implements the NSObject category and test if the 
> delegate implements the method using -respondsToSelector:
> But this way works too if you don't want to have to test before sending your 
> message.
> 
> Anyway, informal protocols are "deprecated" in favor of @protocol with 
> @optional method.
> 
> 
> -- Jean-Daniel
> 
> 
> 
> 


Did not see that it was deprecated, but will take your lead and convert them to 
that. Does the, in your opinion, "optional" addition pretty much replace 
categories as a whole, or is there still a role for them?


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: question about informal protocols

2009-11-20 Thread Jean-Daniel Dupas

Le 20 nov. 2009 à 20:46, Michael de Haan a écrit :

> I am working through an example in  Buck/Yacktman's book that uses an 
> informal protocol.
> 
> In the interface of of a custom class,  it is declared as such.
> 
> 
> #import 
> 
> 
> @interface MyShapeEditorDocument : NSDocument
> {
>ivars
> }
> @end
> 
> 
> @interface NSObject(MYShapeEditingDocEditor)
> 
> 
> 
> -(void) controllerDidEndEditing;
> @end
> 
> 
> In the implementation file it is defined, twice, thus.
> 
> 
> @implementation NSObject(MYShapeEditingDocEditor)
> 
> -(void) controllerDidEndEditing
> {
>   
> }
> @end
> 
> and in the main body of the code, thus.
> 
> 
> @implementation MyShapeEditorDocument
> 
> 
> -(void) controllerDidEndEditing
> {
>[[self myView] setNeedsDisplay: YES];
>[[self table] reloadData];
> }
> 
> 
> Apple's docs say:  "When used to declare a protocol, a category interface 
> doesn’t have a corresponding implementation. Instead, classes that implement 
> the protocol declare the methods again in their own interface files and 
> define them along with other methods in their implementation files."  
> (http://developer.apple.com/mac/library/documentation/cocoa/Conceptual/ObjectiveC/Articles/ocProtocols.html#//apple_ref/doc/uid/TP30001163-CH15-TPXREF147)
> 
> 
> What I am not following is the seemingly double definitions. From the docs, 
> it would seem that implementation is a 2 step process, not a 3 step as above, 
> even though this is clearly correct. What is the essence that I am missing? 


The usual way is to NOT implements the NSObject category and test if the 
delegate implements the method using -respondsToSelector:
But this way works too if you don't want to have to test before sending your 
message.

Anyway, informal protocols are "deprecated" in favor of @protocol with 
@optional method.


-- Jean-Daniel




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com