swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: delegation


From: Sven N. Thommesen
Subject: Re: delegation
Date: Mon, 28 Sep 1998 09:32:31 -0500

At 11:40 AM 9/26/1998 -0400, Rick Riolo wrote:
>
>I believe the example below shows how to delegate from a
>collection, in this case, a List.
>The basic idea is MyList has a List instance variable
>which it creates as a List.
>Then one adds a -forward:: method to MyList,
>plus what other methods one wanted.
>And of course one could add other IV's to MyList.
>As you can see, there is not that much that needs to
>be done versus regular subclassing (ie just add this
>boilerplate forward method).  It does add some
>inefficiency, but I guess we knew there would be some
>of that using objectiveC!

It is also possible, of course, to add to your MyList object all the
methods required by the List protocol, and have MyList just forward those
calls to the internal list:

-(int) getCount
{
  return [list getCount];
}

and so on. Plus whatever additional methods MyList might need.  See the
code in activity/SwarmProcess.m for an example of doing it this way: it
shows how a Swarm forwards Zone messages to an internal Zone object.

The forward:aSelector: method just automates the process, by intercepting
any method calls to methods that are not defined for the MyClass class.

>Note that this works as long as list is created via:
>   list = [List create: scratchZone]; 
>but I tried it also using
>   list = [List create: self];
>which I think is supposed to work for (at least)
>non-delegation cases (but correct me if I'm wrong).

I believe the problem is that while a Swarm is also a Zone (well, it
masquerades as one), a SwarmObject is not. Since MyList is a SwarmObject,
you cannot say 'list = [List create: self]'. However, you should be able to
say 'list = [List create: [self getZone]]'.


Cheers,
--Sven


                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.
                  ==================================


reply via email to

[Prev in Thread] Current Thread [Next in Thread]