Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Mac > BOOK: Beginning Mac OS X Programming
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
BOOK: Beginning Mac OS X Programming
This is the forum to discuss the Wrox book Beginning Mac OS X Programming by Michael Trent, Drew McCormack; ISBN: 9780764573996
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Mac OS X Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 3rd, 2006, 02:43 PM
Registered User
 
Join Date: Mar 2006
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default informal protocol implementation

when categories are mentioned on page 230 the interface file begins:
@interface Person ( MeasurementsCategory )
and the implementation begins:
@implmentation Person ( MeasurementsCategory )

then on page 245 when informal protocols are mentioned, the interface begins:
@interface NSObject (TaskDelegateMethods)
and the implementation begins
@implementation TaskObserver

that confused me, i was wondering why the category wasn't mentioned in the implementation of TaskObserver...is that optional or is it a requirement that it not be there, for inheritance reasons...
  #2 (permalink)  
Old June 3rd, 2006, 12:55 PM
Wrox Author
 
Join Date: Nov 2005
Location: , , .
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

In the example of a category mentioned on page 230, you are extending the functionality of the Person object. Therefore, you write the interface like this:

Code:
@interface Person ( MeasurementsCategory )
...
@end
Once defined you need to implement the methods somewhere. One place to define these methods are in a corresponding implementation block:

Code:
@implementation Person ( MeasurementsCategory )
...
@end
You could also define the methods in the Person object. But the assumption here is its not convenient or possible to modify Person directly (maybe you don't have access to the Person object's source code). Thus, the separate block.

In the second example, you are adding a delegate callout to the Task object. At some point, you are going to give Task an object, and Task is going to message that object at specific times. We would like to use normal method-call syntax on our delegate object. But if we were to write:

Code:
id del = [self delegate];
[del executionShouldBegin:self];
The Objective-C compiler is going to complain that object 'del' might not support the executionShouldBegin: method. We use a category on NSObject to tell the Objective-C compiler that any Objective-C object (descending from NSObject) will respond to executionShouldBegin:, regardless of what it's class actually is. We write that category like so:

Code:
@interface NSObject ( TaskDelegateMethods )
- (BOOL)executionShouldBegin:(Task*)task;
...
@end
Now, it's the delegate object's job to supply the implementation for these functions. That is, if we have a class named TaskObserver, a TaskObserver object might set itself as a Task delegate. The Task delegate will try to send its delegate messages to TaskObserver. The TaskObserver class would just include these methods in its main object interface/implementation.

Code:
@interface TaskObserver : NSObject
{
}
@end

@implementation TaskObserver

- (BOOL)executionShouldBegin:(Task*)task
{
    return YES;
}

....

@end
And that's exactly what we see on page 245.

Hope that helps!

 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Force Protocol Encryption ruchitanu SQL Server 2005 0 May 25th, 2007 02:58 PM
Protocol used for sending a request. m_soni21 Classic ASP Professional 2 December 1st, 2006 11:41 AM
What is the protocol to summit corrections to the tbroom BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 5 August 16th, 2006 12:48 PM
file protocol and non-IE browsers nemo-x HTML Code Clinic 1 July 19th, 2004 07:50 AM
Internet Transfer Protocol sporkman43 VB.NET 0 June 16th, 2004 08:45 AM



All times are GMT -4. The time now is 03:49 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.