[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6. Advanced Topics


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.1 Forwarding

When an object is unable to respond to a message, the Objective-C runtime sends a forwardInvocation: message to the object, and the object is then able to use the information provided to handle the message in some way, a common mechanism being to forward the message to another object known as a delegate, so that the other object can deal with it.

 
- (void) forwardInvocation: (NSInvocation*)objectInvoke
{
  if ([forwardObject respondsToSelector: [objectInvoke selector]])
    return [objectInvoke invokeWithTarget: forwardObject];
  else
    return [self doesNotRecognizeSelector: [objectInvoke selector]];
}

Note. this is a powerful method for creating software patterns for multiple inheritance, journaling, and dispatching messages to dynamically loaded code.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.1.1 Forwarding and Multiple Inheritance

Forwarding is a form of multiple inheritance. The diagram below shows a simple scenario where an instance of the Chat class passes the negotiate message to an instance of the ChatTwo class. The forwarding object therefore inherits methods from its own inheritance path and from that of the receiving object.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.1.2 Surrogate Objects

Surrogate objects forward messages to objects that can be assumed to be more complex. The forwardInvocation: method of the surrogate object receives a message that is to be forwarded; it determines whether or not the receiver exists, and if it does not, then it will attempt to create it. A proxy object is a common example of a surrogate object. A proxy object performs obvious functions that we have already discussed:


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.1.3 Forwarding vs Inheritance

The main difference between Forwarding and Inheritance surfaces in the application of methods like respondsToSelector and isKindOfClass:. This is because these methods search the inheritance path, but ignore the forwarding path.

(See Section 1.6.6 respondsToSelector.)

Note. respondsToSelector does not trace the forwarding chain, and can therefore erroneously report that an object does not respond to a particular message, when it does.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.2 Exception Handling


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.3 Copying, Comparing, Hashing Objects


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.4 Dictionaries, Arrays, Containers


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.5 Coding


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.6 Property Lists


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.7 Bundles


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.8 UserDefaults


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.9 Threading

General discussion about threading with gnustep base, what is thread-safe, what is not, how to start new threads, NSThread briefly introduced with examples.

[Nicola: important: talk about NSConnection enableMultipleThreads]].


[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by root on December, 20 2003 using texi2html