Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Apple should get behind Cocoa Java



On Aug 24, 2006, at 8:59 AM, Hsu wrote:

Delegation is distinct from interfaces & far more powerful. It is part of the runtime as you mentioned, but Cocoa==Obj-C like JavaVM==Java. Java actually took the concept of interfaces from Objective-C where they are called protocols.

I never said that delegation and interfaces are the same thing. I said that delegation can be implemented using interfaces.

IMHO, Interfaces are a poor way to implement delegation; once fixed they cannot be easily extended without breaking client code.


Karl

Karl's comment got me to re-evaluate my understanding of the delegate mechanism in Cocoa and I think I was a bit too quick in my statement that delegation can be *easily* implemented with interfaces.


Niels is right in that delegation is a more powerful concept than that of interfaces, and so is Karl in that interfaces are a poor way to implement delegation.

For the benefit of others who, like me, are experienced Java programmers but Cocoa newbies, let me elaborate a bit on this.

Cocoa's delegation mechanism does not *require* a delegate object to implement a particular delegate method whereas Java interfaces are a strict bonding contract between the method caller and the interface implementer.

As a result, adding a new method to an interface will require clients to change their code, even if they're not interested in actually using the new method. Cocoa delegate clients couldn't care less and won't *have* to change.

As it turns out, there's a way around, namely, using the Adapter pattern. The problem with Adapters, though, is that they're not interfaces but actual classes, and that forces a delegate to belong to a fixed class hierarchy.

On the flip side, protocols (the Obj-C analog of interfaces) aren't binding, so you can't be *guaranteed* that a class implementing a particular protocol will implement *all* of its methods.

It seems to me, then, that there's room for improvement in both languages. A new language might have three distinct kinds of types: classes, interfaces, and delegates. Classes force a particular hierarchy, Interfaces impose a bonding contract, and Delegates form a relaxed interface, not requiring its methods to be implemented.

Thank you, Karl, for getting me to rethink my position. :)

Wagner
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden
References: 
 >Re: Apple should get behind Cocoa Java (From: Wagner Truppel <email@hidden>)
 >Re: Apple should get behind Cocoa Java (From: Hsu <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.