On Sep 18, 2010, at 11:14 AM, Ken Tozier wrote:

> I'm writing two apps: A server and client and am having some trouble figuring 
> exactly what to link to in the client program. The server application has a 
> main class that has dozens of dependencies. I don't want to have to import 
> all the server app dependencies into the client application as that defeats 
> the purpose of factoring code into separate apps. How do I send messages to a 
> server's vended object without having to include the server's entire 
> dependency tree? I looked into protocols and proxies but am not sure which to 
> use.

The client shouldn't have or need any of the server's implementation code.  You 
should define a protocol for the interface to the vended object in a header 
that's shared by both the client and the server.

Then, cast the NSDistantObject* pointer returned by one of the rootProxy... 
methods to NSDistantObject<YourProtocolHere>* (or, if you prefer, 
id<YourProtocolHere>).  Then, just invoke the appropriate methods on it.

The client should also use -[NSDistantObject setProtocolForProxy:] for 
efficiency.  And the server should probably vend an NSProtocolChecker instead 
of the actual object.  Any actual object is likely to have a number of private 
or internal-use-only methods on it, which you don't want accessible from 
client.  The NSProtocolChecker makes sure that only the appropriate methods are 
accessible.

The client code should have no mention of the actual class used on the server.

Regards,
Ken

_______________________________________________

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

Reply via email to