Skip navigation.
 
mlRe: Distributed Objects, copying thereof
FROM : Philip Mötteli
DATE : Thu Jun 08 21:16:10 2006

Am 08.06.2006 um 20:16 schrieb Jim Thomason:

>> To send an object "across the wire" in DO, your object needs to 
>> implement
>> the NSCoding protocol. As an additional note (that I didn't 
>> encounter in
>> Apple docs), the object that does the coding in DO (NSPortCoder, I 
>> believe)
>> does not seem to support keyed coding, so be sure your 
>> encodeWithCoder: and
>> initWithCoder: methods are old school, and not keyed.
>>
>> Your object also needs to also implement the following method, in 
>> order to
>> tell the NSPortCoder to package up and send your actual object 
>> contents, not
>> just a reference to the object:
>> - (id)replacementObjectForPortCoder:(NSPortCoder *)encoder
>> {
>>    if ([encoder isByref]){
>>        return [NSDistantObject proxyWithLocal:self connection:
>> [encoder
>> connection]];
>>    } else {
>>        return self;
>>    }
>> }

>
> Recall - I'm using NSBezierPaths and NSImages. Those are all that I'm
> sending across the wire. Built in apple classes. Merely adding in the
> bycopy keyword isn't enough to make my code work, no, I actually do
> need to implement replacementObjectForPortCoder:
>
> But, these are apple's classes, not my own. So I'm adding on
> categories to NSImage and NSBezierPath to do nothing more than
> implement this boilerplate method. And that works just fine.
>
> So why oh why didn't Apple just implement that little boilerplate
> version as NSObject's default? As I understand the docs now,
> NSObject's always returns a distant proxy and apparently completely
> ignores NSPortCoder's byref/bycopy/etc flags, which in turn requires
> me to tack on a category to implement a more useful version.
>
> Am I way off base, or does this strike anyone else as being really 
> silly?


It did strike me too.
It gets even worse: Arrays are always copied. This is very annoying 
when using HOMs.
One can simply say, that the ObjC keyword "bycopy" doesn't serve for 
anything at all.
So what I did, was that I exchanged NSObject's -
replacementObjectForPortCoder: for this:

- PMreplacementObjectForPortCoder:(NSPortCoder *)aCoder
{
   return [aCoder isBycopy] ? self : [self 
origReplacementObjectForPortCoder:aCoder];
}

This way, I'm sure, that an object will be copied, when I want it to 
be. I can decide that in my code and don't have to implement that on 
a class basis all over the place.
In my eyes, this is a bug.


Re
Phil

Related mailsAuthorDate
mlDistributed Objects, copying thereof Jim Thomason Jun 8, 18:23
mlRe: Distributed Objects, copying thereof John Pannell Jun 8, 18:49
mlRe: Distributed Objects, copying thereof Jim Thomason Jun 8, 20:16
mlRe: Distributed Objects, copying thereof Philip Mötteli Jun 8, 21:16
mlRe: Distributed Objects, copying thereof Jim Thomason Jun 9, 02:34
mlRe: Distributed Objects, copying thereof John Pannell Jun 9, 03:09
mlRe: Distributed Objects, copying thereof Chris Kane Jun 9, 20:21